php - PHPMailer SMTP issue -
i want use phpmailer send out emails, have html form collects necessary data such username, password, recipient, subject , html template.
so have downloaded phpmailer library , trying config can send out emails, getting error: smtp connect() failed. message not sent.mailer error: smtp connect() failed.
debuting purposes have used $mail->smtpdebug =1;
, error says 2014-03-24 11:13:13 smtp error: failed connect server: (0) smtp connect() failed. message not sent.mailer error: smtp connect() failed.
i working on localhost (mamp) error says there problem smtp server using (smtp.gmail.com) have tried change local host error same.
i belief there configuration issues
my code:
<?php session_start(); if(isset($_request['submit'])){ $email = array(); $email['email_to'] = $_post['recipient']; $email['subject'] = $_post['subject']; $email['html'] = $_post['template']; require 'phpmailer/phpmailerautoload.php'; require ('phpmailer/class.phpmailer.php'); require ('phpmailer/class.smtp.php'); $mail = new phpmailer; $mail->issmtp(); // set mailer use smtp $mail->host = 'smtp.gmail.com'; // specify main , backup server $mail->smtpauth = true; // enable smtp authentication $mail->username = $_session['username']; // smtp username $mail->password = $_session['password']; // smtp password $mail->smtpsecure = 'ssl'; // enable encryption, 'ssl' accepted $mail->from = $_session['username']; $mail->fromname = 'tomasz'; $mail->addaddress($email['email_to']); // add recipient $mail->addaddress('ellen@example.com'); // name optional $mail->addreplyto($_session['username']); $mail->addcc('cc@example.com'); $mail->addbcc('bcc@example.com'); $mail->wordwrap = 50; // set word wrap 50 characters $mail->addattachment('/var/tmp/file.tar.gz'); // add attachments $mail->addattachment('/tmp/image.jpg', 'new.jpg'); // optional name $mail->ishtml(true); // set email format html $mail->subject = $email['subject']; $mail->body = $email['html']; $mail->altbody = 'this body in plain text non-html mail clients'; $mail->smtpdebug =1; if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error: ' . $mail->errorinfo; exit; } echo 'message has been sent'; }
could suggest how can fix this...?
Comments
Post a Comment