-3

我有以下用于发送邮件的代码:

$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    
}

邮件发送正常,但我需要在消息中显示电话号码。我相信这很容易解决,我会全力以赴!当有人教我的时候,让我们结束吧!:)

4

3 回答 3

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    
}
于 2013-01-18T19:39:47.447 回答
0

将电话号码放入$message变量中。就像是

$message = $_POST['message']."<br/><br/>Your phone number is: ".$phone;

还要添加适当的标题以支持 HTML:

$headers .= "Content-Type: text/html\r\n"; 
于 2013-01-18T19:39:02.953 回答
0

您需要将电话号码连接到消息才能发送。

$message = $_POST['message']."\n\n$phone";

您还应该查找防止电子邮件注入的功能,并在每个帖子值上运行 strip_tags 以防止对您的表单进行 XSS 攻击。

于 2013-01-18T19:40:44.607 回答