0

when using the script i get the following : Fatal error: Call to undefined method PEAR_Error::send()

this is my script:

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!")');
}
}
}

2 Answers2

0

You dont need foreach. Try this code

 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!")');
}

}

if you want to send multiple people separate "to" variable with "comma"

0

Probably some login failure. This means you got error object, not mail object.

Check for error and before send:

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

$mail = $smtp->send($to, $headers, $msg);
...
Ivan Vulović
  • 2,147
  • 6
  • 27
  • 43