从ubuntu虚拟机发送电子邮件并使用catchmail:无法执行:smtp:// localhost:1025

时间:2012-10-26 12:19:08

标签: php email phpmailer

我在我的虚拟机上使用ubuntu。我想使用catchmail发送电子邮件,如下所述:http://berk.es/2011/05/29/mailcatcher-for-drupal-and-other-php-applications-the-simple-version/

我正在尝试发送这样的电子邮件:

//Mailer class:
class Mailer extends PHPMailer
{
public $UTF8Encode = false;
public function __construct($param = null)
{   
    parent::__construct($param);
    $this->Mailer = 'sendmail';
    $this->Sendmail = 'smtp://localhost:1025';
    $this->From   = 'xxxx@xxxx.com';
    $this->FromName = 'Support';
    $this->WordWrap = 50;
    $this->CharSet = 'UTF-8';
}
}

....etc....

并且:

//Sending emails

$mail = new Mailer();
$mail->Body = "xxxx";
$mail->Subject = "xxx";
$mail->From = 'xxxx@xxxx.org';
$mail->FromName = 'Support';
$mail->WordWrap = 50;
$mail->AddAddress(xxxx@xxxx.com);

我收到错误:

Could not execute: smtp://localhost:1025

1 个答案:

答案 0 :(得分:1)

$this->Mailer = 'sendmail';
$this->Sendmail = 'smtp://localhost:1025';

问题在于你告诉PHPMailer使用名为sendmail的命令行程序而不是使用smtp。 PHPMailer尝试做类似的事情:

exec("smtp://localhost:1025 --args-and-stuff");

正如你所知,这不起作用。

要告诉PHPMailer使用smtp,您需要执行以下操作:

$this->Mailer = 'smtp';
$this->Host = 'localhost';
$this->Port = 1025;

如果您的SMTP服务器需要验证,您可以按照以下方式执行此操作:

$mail->SMTPAuth = true;
$mail->Username = "yourname@yourdomain";
$mail->Password = "yourpassword";