使用 Zend Framework 和 PHP 发送电子邮件
我正在制作一个表单,当用户输入他们的电子邮件帐户并单击发送时,一封电子邮件将发送到他们的电子邮件帐户。
我已经把一切都解决了。只是它不会将电子邮件发送到我的帐户。有人有什么想法吗?是否有我遗漏的配置或其他什么?
这是我的控制器的示例:
public function retrieveemailAction(){
$users = new Users();
$email = $_POST['email'];
$view = Zend_Registry::get('view');
if($users->checkEmail($_POST['email'])) {
// The Subject
$subject = "Email Test";
// The message
$message = "this is a test";
// Send email
// Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
// Use if command to display email message status
if(mail($email, $subject, $message, $headers)) {
$view->operation = 'true';
}
} else {
$view->operation = 'false';
}
$view->render('retrieve.tpl');
}
I working on a form whereby when the user enter in their email account and click on send, an email will be sent to their email account.
I have everything worked out. Just that it doesnt send the email to my account. Anyone have any ideas? Is there a configuration that I left out or something?
This is the sample from my controller:
public function retrieveemailAction(){
$users = new Users();
$email = $_POST['email'];
$view = Zend_Registry::get('view');
if($users->checkEmail($_POST['email'])) {
// The Subject
$subject = "Email Test";
// The message
$message = "this is a test";
// Send email
// Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
// Use if command to display email message status
if(mail($email, $subject, $message, $headers)) {
$view->operation = 'true';
}
} else {
$view->operation = 'false';
}
$view->render('retrieve.tpl');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议您使用
Zend_Mail
而不是mail()
。它会自动处理很多事情,而且效果很好。您有 SMTP 服务器吗?尝试在没有您自己的 SMTP 服务器的情况下发送邮件可能会导致邮件无法发送。
这是我使用
Zend_Mail
和 Gmail 发送邮件的方法:在
Bootstrap.php
中,我配置了默认邮件传输:然后,要发送电子邮件,我使用以下代码:
I recommend you use
Zend_Mail
instead ofmail()
. It handles a lot of stuff automatically and just works great.Do you have a SMTP server? Trying to send mail without your own SMTP server could be causing the mail to not be sent.
This is what I use for sending mails using
Zend_Mail
and Gmail:In
Bootstrap.php
, I configure a default mail transport:Then to send an email I use the following code:
首先我会改用 Zend_Mail。其次,我会在某处的 smtp 服务器上使用真实的邮件帐户并从该服务器发送。很多时候从服务器本身发送是有限制的,但是使用实际的邮件服务器通常可以解决这个问题。
First of all i would switch to using Zend_Mail. Second i would use a real mail account on an smtp server somewhere and send from that. A lot of times there are restrictions on sending from the server itself, but using an actual mail server usually fixes this.
ZendCasts 上有一个非常有用的涵盖 Zend_Mail 的截屏视频
http://www.zendcasts.com/introduction-to-zend_mail/2010 /02/
There's a very useful screencast covering Zend_Mail available on ZendCasts
http://www.zendcasts.com/introduction-to-zend_mail/2010/02/
在
$mail->setBody($message);
行中,将其更改为$mail->setBodyText($message);
In line
$mail->setBody($message);
, change it to$mail->setBodyText($message);