繁体   English   中英

无法使php mail()工作

[英]Can't get php mail() to work

我的Mac上运行了Mamp,并试图使mail()正常工作。

这就是我要处理的。

$to = 'mymail@gmail.com';
$subject = 'The subject!';
$message = 'Hi there!';


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
$headers .= 'From: Test <test@test.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


// Mail it
if(mail($to, $subject, $message, $headers))
{ print 'success!'; }
else
{ print 'fail!'; }

?>

它只是不断返回false。 知道我在做什么错吗? 我需要检查php / apache的一些设置吗?

如果您在本地主机上使用代码段,请放在服务器上,然后尝试。 如果您想运行php mail()函数,则必须将其关闭。 在本地主机上,您总是会失败!

尝试这个:

<?php
$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

ini_set('sendmail_from', 'me@domain.com');

mail($recipient, $subject, $mail_body, $header);
?>

http://be.php.net/manual/zh/function.mail.php

每行文字不得超过70个字符,需要用LF(\\ n)隔开

编辑:如@brad建议:SwiftMailer真的很好!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM