PHP and HTML feedback form

…衆ロ難τιáo~ 提交于 2019-12-04 21:40:53

It's:

$content = "New contact form submission \n From: ".$name.",\n Email: ".$email.", \n Message: ".$message;

and

<textarea name="message" rows="10" cols="50"></textarea>

Start using Swiftmailer or PhpMailer, your life will be easier...

Swiftmailer example:

require_once 'lib/swift_required.php';
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
    ->setFrom(array('john@doe.com' => 'John Doe'))
    ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
    ->setBody('Here is the message itself');
$mailer->send($message);

PhpMailer example :

$mail             = new PHPMailer(); // defaults to using php "mail()"
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->AddAddress("whoto@otherdomain.com", "John Doe");
$mail->Subject    = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

I prefer Swiftmailer, but you select you best choice ;-)

Wrap the variable names in curly braces. E.g. "From:,{$name},"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!