我正在尝试制作一个html和php反馈表单,我收到的电子邮件如下:
New contact form submission
From:,,
Email:,@email,
,,
我的HTML是:
<form method="POST" action="contactform.php">
Name:<br/>
<input type="text" name="name" />
<br/><br/>
EMail:<br/>
<input type="text" name="email" />
<br/><br/>
Message: <br/>
<textarea name"message" rows="10" cols="50" />
</textarea><br/>
<input type="submit" value="submit" />
</form>
我的php是:
<?php
//converting veriables
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$recipient = 'nicholasparry@me.com';
$subject="Contact Form";
//creating message
$content = "New contact form submission \n From:,$name, \n Email:,@email, \n ,$message,";
//sending message
mail($recipient, $message, $content);
?>
任何人都可以帮我解决错误吗?
答案 0 :(得分:4)
这是:
$content = "New contact form submission \n From: ".$name.",\n Email: ".$email.", \n Message: ".$message;
和
<textarea name="message" rows="10" cols="50"></textarea>
答案 1 :(得分:0)
开始使用Swiftmailer或PhpMailer,您的生活会更轻松......
Swiftmailer示例:
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示例:
$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!";
}
我更喜欢Swiftmailer,但你选择了你最好的选择; - )
答案 2 :(得分:0)
用花括号包装变量名。例如。 “从:{$名称}”