我正在使用CakePHP发送电子邮件。我的控制器代码如下所示:PHP邮件()不发送,但不会抛出异常
if ($this->User->save($this->request->data)) {
$email = new CakeEmail();
$email->from(array('[email protected]' => 'My Domain'));
$email->to($this->request->data['User']['email']);
$email->subject('My Domain Confirmation');
$email->replyTo('[email protected]');
$email->sender('[email protected]', 'My Domain');
$email->emailFormat('html');
$email->template('confirmation');
$email->send();
$email->viewVars(array(
'name' => $this->request->data['User']['username'],
'id' => $this->User->getLastInsertID(),
'code' => $this->request->data['User']['confirm_code']));
}
我也包括在这个控制器的顶部: App::uses('CakeEmail', 'Network/Email');
如果我的print_r对$的电子邮件 - >发送(),我得到:
Array
(
[headers] => From: My Domain
Reply-To: [email protected]
X-Mailer: CakePHP Email
Date: Thu, 23 Feb 2012 00:40:00 -0800
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
[message] =>
Hi there,
Welcome to my site! While you can now vote on submissions and leave comments, your own submissions will be screened and not appear to the public until you click on the confirmation link below:
Click here to confirm your account
We hope to see you around and thanks for joining the community!
所以很明显使用我的html电子邮件模板并将正确的变量传递给它,并且不会抛出异常。所以我决定只是做我的视图文件例如为:
$to = "myte[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
哪一个呼应内的基本的邮件()测试“已发送邮件”,但没有实际来我的邮箱。我在/var/spool/mail/root
中检查了我的文件,并且2012年1月9日发送的最后一封电子邮件在同一台服务器上。所以它绝对有效。我刚刚升级到Cake 2.0,但这并不能解释为什么普通ol'mail()
不起作用。
还有哪些其他调试方法可以检查以确保它不是我的服务器,防止发送电子邮件?
您的MTA是否正在运行?如果没有,你会看到这种行为(和所有的邮件发送,当你启动它) – 2012-02-23 09:08:05
有一个在Apache错误日志(但如果它在那里你应该看到它),并在邮件错误日志 – Mike 2012-02-23 09:09:45
检查你的apache日志,也让你添加在你的PHP文件的顶部'ini_set('display_errors','On'); error_reporting(E_ALL);'以确保你也得到通知和警告。 – 2012-02-23 09:17:14