我有一个很难得到下面的代码运行:PHP邮件发送问题
$name = 'Kevin';
$company = 'nonw';
$website = 'none';
$email = '[email protected]';
$phone = 'none';
$message = 'Just a test message.';
$message = "<ul>
<li><strong>From:</strong> $name</li>
<li><strong>Company:</strong> $company</li>
<li><strong>Website:</strong> $website</li>
<li><strong>Email:</strong> $email</li>
<li><strong>Phone:</strong> $phone</li>
</ul>
<p>$message</p>";
$subject = '[' . $sitename . '] New contact message from ' . $name . ' (' . $email . ')';
$headers = 'From: ' . $sitename . ' <' . $to . '>\r\nReply-To: ' . $email . '\r\n';
$s = mail($subject, $message, $email, $to);
if($s){
echo '<div class="msg">Your message has been sent. Thank you for contacting us, someone will be in touch soon.</div>';
}else{
echo '<div class="err">There was an error sending your message. Please try again later.</div>';
print_r(error_get_last());
}
我在php.ini中有这样的:
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "/usr/sbin/sendmail -t -i -f [email protected]"
也曾尝试用:
sendmail_path = "/usr/sbin/sendmail -t -i"
我已验证服务器设置正确,通过直接在服务器上运行此服务器echo "test" | mail -s "test mail" [email protected]
和I收到了电子邮件。
可能会发生什么,或者更重要的是...我错过了什么?
你得到任何错误,当您运行脚本?哪个div显示?在进行mail()调用之前,尝试为您的各个变量添加一个'var_dump()',以确保您传递的是正确的信息。 – zajd
我是一个傻瓜....你会在一分钟内看到为什么 – Kevin