0

使用脚本时,我得到以下信息:致命错误:调用未定义的方法 PEAR_Error::send()

这是我的脚本:

if ($_POST['start']){
$from = $_POST['from'];`enter code here`
$name = $_POST['fromnm'];
$msg = $_POST['msg'];
$sender = explode("\r\n", $_POST['to']);
$headers .= 'From:' . $name . "<" . $from . ">"  . "\n";
$headers .= 'Reply-To:' . $from . "\n";
foreach($sender as $to) {

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'facebook.mailer.test@gmail.com',
        'password' => '12563254'
    ));

$mail = $smtp->send($to, $headers, $msg);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<script>alert("Message Sent!")');
}
}
}
4

2 回答 2

0

可能是一些登录失败。这意味着你得到了错误对象,而不是邮件对象。

检查错误和发送前:

$smtp = Mail::factory(...)
if (PEAR::isError($smtp)) {
    echo('<p>' . $mail->getMessage() . 'and' .$mail->getUserInfo(). '</p>');
}

$mail = $smtp->send($to, $headers, $msg);
...
于 2014-09-21T10:28:51.970 回答
0

你不需要foreach。试试这个代码

 if ($_POST['start']){
    $from = $_POST['from'];
    $name = $_POST['fromnm'];
    $msg = $_POST['msg'];
    $to = $_POST['to'];
    $headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $name 
);



$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'facebook.mailer.test@gmail.com',
        'password' => '12563254'
    ));

$mail = $smtp->send($to, $headers, $msg);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<script>alert("Message Sent!")');
}

}

如果您想用“逗号”向多个人发送单独的“to”变量

于 2014-09-21T10:13:44.730 回答