这是我用来测试我的某个表单的电子邮件发送的PHP代码。虽然它运作良好,但由于某种原因它附加 @ localhost.mydomain.com到发件人的电子邮件地址。这是一个例子:
From: James <james.bond@hotmail.com@localhost.mydomain.com>
以下是完整的代码。
<?php
$email = sqlEscape($_POST['email']);
$name = sqlEscape($_POST['name']);
$to = 'me@yahoo.com';
$subject = 'Email From website';
$message = 'The message here';
$headers = 'From: "'.$name.'" <"'.$email.'">' . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
if(mail($to, $subject, $message, $headers)){
echo('Message sent successfully');
}else{
echo('<a href="contact.php">Click here</a> to try again.');
}
?>
有没有办法让它不附加它?感谢
答案 0 :(得分:0)
你试过了吗?
ini_set(sendmail_from,$_POST['email']);
?
在mail()函数调用之前添加此行。