我正在尝试使用PEAR邮件通过外部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";
发布于 2010-02-18 05:37:35
尝试以下操作以确保您的邮件正常工作:
<?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。
发布于 2013-01-03 06:08:42
如果有人在linux上运行,并且遇到了与Jayme相同的问题。这是另一个安装缺少的"Net/“类的简单解决方案。这些缺少的类会导致脚本中断。
sudo pear install Net_SMTP
发布于 2011-07-08 00:21:12
我遇到了同样的问题,它挂起了send命令。我的第一步是从命令行运行,以查看完整的错误消息(正如Rap上面建议的那样)。
php mymailsample.php
它会输出以下内容
Warning: include_once(Net/SMTP.php): failed to open stream: No such file or directory in mail/Mail/smtp.php on line 348
PHP Warning: include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/lib/php') in mail/Mail/smtp.php on line 348
PHP Fatal error: Class 'Net_SMTP' not found inmail/Mail/smtp.php on line 349
我下载了以下代码,并将它们放在/Net中
http://pear.php.net/package/Net_SMTP/download
http://pear.php.net/package/Net_Socket/download
我必须调整SMTP和套接字库的权限,以便Apache可以读取它们。
瞧,它成功了!
https://stackoverflow.com/questions/2284468
复制相似问题