PHP PEAR Mail的问题 [英] Problem with PHP PEAR Mail

查看:90
本文介绍了PHP PEAR Mail的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PEAR Mail通过外部smtp服务器发送邮件.它似乎挂了一段时间,然后脚本结束了.它一直输出我所有的"echo"语句,直到发送完之后.除了显示发送之前"的回声之外,没有任何输出.谁能告诉我这里可能出什么问题了吗? (用虚拟值代替smtp值).邮件未发送.感谢您的帮助!

I am trying to use PEAR Mail to send using an external smtp server. It seems to hang for a while, then the script ends. It outputs all of my "echo" statements up till the one after the send. Nothing is output past the echo that says "before send". Can anyone tell me what might be wrong here? (dummy values substituted for smtp values). Mail is not being sent. Thanks for helping!

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";

推荐答案

尝试以下操作以确保您的邮件正常运行:

Try this to ensure your mail is working:

<?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配置.

If this does not work then you will need to check your PHP Configuration.

请参见 http://php.net/manual/en/function.mail.php 了解更多信息.

这篇关于PHP PEAR Mail的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆