我有以下发送邮件的代码:
$email_to = 'someone@somewhere.com';
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: ' . $name . ' <' . $email_to . '>' . "\r\n" . 'Reply-To: ' . $email;
if(mail($email_to, $subject, $message, $headers)) {
echo 'sent'; // sending this text to the ajax request telling it that the mail is sent..
} else {
echo 'failed'; // ... or this one to tell it that it wasn't sent
}
邮件发送正常,但我需要显示电话号码和邮件。我确信这是一个简单的解决方案,我会全部“嗯!”当有人给我上学的时候,让我们来完成吧! :)
答案 0 :(得分:2)
您需要将电话号码附加到消息字符串中。
$email_to = 'someone@somewhere.com';
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'] . "\n\n" . $phone;
$headers = 'From: ' . $name . ' <' . $email_to . '>' . "\r\n" . 'Reply-To: ' . $email;
if(mail($email_to, $subject, $message, $headers)) {
echo 'sent'; // sending this text to the ajax request telling it that the mail is sent..
} else {
echo 'failed'; // ... or this one to tell it that it wasn't sent
}
答案 1 :(得分:0)
将电话号码放在$message
变量中。像
$message = $_POST['message']."<br/><br/>Your phone number is: ".$phone;
还要添加适当的标头以支持HTML:
$headers .= "Content-Type: text/html\r\n";
答案 2 :(得分:0)
您需要将电话号码连接到邮件以便发送邮件。
$message = $_POST['message']."\n\n$phone";
您还应该查找防止电子邮件注入的功能,并在每个帖子值上运行strip_tags以防止对您的表单进行XSS攻击。