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 に答える