0

我正在尝试在本地主机上的 zend 框架中发送电子邮件。

以下是我的代码:

$mail = new Zend_Mail('utf-8');
        $mail->addTo($email);
        $mail->setSubject('Welcome');
        $mail->setFrom('test@user.com', 'test@user.com');
        $mail->setBodyText($bodyText);
        $sent = true;

        // Send the email
        try {
            $mail->send();
        } catch (Exception $e) {
            echo "<pre>";
            print_r($e);
            exit;
            $sent = false;
        }
        return $sent;

但它显示以下异常:

[message:protected] => 无法发送邮件。mail() [function.mail]:无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 ini_set()

以下是我在 php.ini 中的设置

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25


; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = test@user.com

我正在使用 PHP 版本 5.3.9,Wampserver 2.2。

如何解决此错误?

4

1 回答 1

2

试试这个链接如何使用本地主机发送邮件

//Prepare email
$mail = new Zend_Mail();
$mail->addTo($email);
$mail->setSubject($subject);
$mail->setBody($message);
$mail->setFrom('username@gmail.com', 'User Name');

//Send it!
$sent = true;
try {
    $mail->send();
} catch (Exception $e){
    $sent = false;
}

//Do stuff (display error message, log it, redirect user, etc)
if($sent){
    //Mail was sent successfully.
} else {
    //Mail failed to send.
}

或试试这个链接Sending email using Zend Framework and PHP

于 2013-02-01T06:42:13.447 回答