2

i m using phpmailer class for sending emails. i m geeting error "Could not execute: /smtp" the following code the code is below. can someone suggest me what is the problem.

require '../class.phpmailer.php'; 

try {
    $mail = new PHPMailer(true); //New instance, with exceptions enabled

    $body             = file_get_contents('contents.html');
    echo $body;
    $body             = preg_replace('/\\\\/','', $body); //Strip backslashes

    $mail->IsSMTP();                           // tell the class to use SMTP
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Port       = 25;                    // set the SMTP server port
    $mail->Host       = "ssl://smtp.gmail.com"; // SMTP server
    $mail->Username   = "test@gmail.com";     // SMTP server username
    $mail->Password   = "1234567889";            // SMTP server password

    $mail->IsSendmail();  // tell the class to use Sendmail

    $mail->AddReplyTo("rto@gmail.com","First Last");

    $mail->From       = "from@gmail.com";
    $mail->FromName   = "First Last";

    $to = "toemail@gmail.com";

    $mail->AddAddress($to);

    $mail->Subject  = "First PHPMailer Message";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->WordWrap   = 80; // set word wrap

    $mail->MsgHTML($body);

    $mail->IsHTML(true); // send as HTML

    $mail->Send();
    echo 'Message has been sent.';
} catch (phpmailerException $e) {
    echo $e->errorMessage();
}
Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
Deepa
  • 1,201
  • 5
  • 15
  • 23

1 Answers1

4

By using GMail, your settings might likely not be correct; try these (corrected port and SSL address):

$mail->Port       =  465;                   // set the SMTP server port
$mail->Host       = "ssl://smtp.gmail.com"; // SMTP server
$mail->Username   = "test@gmail.com";       // SMTP server username
$mail->Password   = "1234567889";   

Alternatively, use TLS:

$mail->Port       =  587;                   // set the SMTP server port
$mail->Host       = "tls://smtp.gmail.com"; // SMTP server

Edit: Remove this line below (You first provide settings to use SMTP, then you tell it to use and send trough sendmail and you put a wrong path in configs. Just stick to one service, use SMTP with above settings (or edit2 below) and see):

Remove:

$mail->IsSendmail();  // tell the class to use Sendmail

Edit2: other option (in case the first answer don't work):

$mail->SMTPSecure = 'ssl'; 
$mail->Host = 'smtp.gmail.com';
danielpopa
  • 810
  • 14
  • 27
Damien Pirsy
  • 25,319
  • 8
  • 70
  • 77
  • i changed the code but still the problem remains.Could not execute: /smtp – Deepa Jun 11 '11 at 09:04
  • @Deepa you should give us further information, then, stating clearly the error message your receive. – Damien Pirsy Jun 11 '11 at 09:04
  • in class.phpmailer.php, public function IsSendmail() { if (!stristr(ini_get('sendmail_path'), 'sendmail')) { $this->Sendmail = '/var/qmail/bin/sendmail'; } $this->Mailer = 'sendmail'; } i just changed the sendmail path to '/smtp'. – Deepa Jun 11 '11 at 09:06
  • @Deepa Updated answer, remove the IsSendmail line – Damien Pirsy Jun 11 '11 at 09:09
  • 1
    if i remove $mail->IsSendmail(); then new error "SMTP Error: Could not connect to SMTP host. " – Deepa Jun 11 '11 at 09:19
  • @Deepa Did you also try using the settings I provided in Edit2? (adding SMTP secure and changing the host). The port is correct, I usually use ssl://... when connecting to gmail and always work, though...Email and password are correct? – Damien Pirsy Jun 11 '11 at 09:22
  • @Deepa try with ssl://smtp.gmail.com instead of what I wrote before (see I have corrected my answer) – Damien Pirsy Jun 11 '11 at 09:24
  • but i m geetting path problem Could not execute: //var/qmail/bin/sendmail. is these are linked really – Deepa Jun 11 '11 at 09:26
  • @Deepa but are you on a localhost? – Damien Pirsy Jun 11 '11 at 09:27