内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/2284468/problem-with-php-pear-mail
我正在尝试使用PEAR Mail使用外部smtp服务器发送.似乎挂了一段时间,然后脚本结束.它输出我的所有“echo”语句直到发送后一个.没有任何东西输出通过说“发送之前”的回声.任何人都可以告诉我这里可能有什么问题吗? (虚拟值代替smtp值).邮件没有发送.感谢您的帮助!
echo "start"; $n = $_POST['txtName']; $e = $_POST['txtEmail']; $t = 'Kenny <email@host.com>'; $f = 'Kenny <email@host.com>'; $s = 'CPA TEST'; $b = "name: $n email: $e"; include("mail.php"); echo "after include"; /* mail setup recipients, subject etc */ $recipients = $t; $headers["From"] = $f; $headers["To"] = $t; $headers["Subject"] = $s; $mailmsg = $b; /* SMTP server name, port, user/passwd */ $smtpinfo["host"] = "my_smtp_host"; $smtpinfo["port"] = "25"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "my_email"; $smtpinfo["password"] = "my_password"; echo "before object"; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); echo "before send"; /* Ok send mail */ $send = $mail_object->send($recipients, $headers, $mailmsg); echo "after send"; if (PEAR::isError($send)) { print($send->getMessage());}else{print "end";} echo "done";
尝试这样做,以确保您的邮件正常工作:
<?php require_once "Mail.php"; $from = "Sandra Sender <sender@example.com>"; $to = "Ramona Recipient <recipient@example.com>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?>
如果这不行,那么您将需要检查您的 PHP 配置.
有关详细信息,请参阅 http://php.net/manual/en/function.mail.php .
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/2284468/problem-with-php-pear-mail
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- SpringBoot邮件发送css样式在手机邮件中显示失效问题
- 解决jenkins 发送邮件图片乱码问题
- 8 亿邮件地址遭泄露,源于邮件验证服务
- 卓越的安全专家临时邮件管家U-Mail邮件网关
- SpringBoot系列(十四)集成邮件发送服务及邮件发送的几种方式
- Android 快速发送邮件
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。