-2

i want to send details from a form using the phpmailer function but i have the error:

SMTP connect() failed. message could not be sent.

mailer error:SMTP connect() failed.

//start of phpmailer
<?php
mailer error:SMTP connect() failed.
  require_once '_libs/PHPMailer/PHPMailerAutoload.php';
$m= new PHPMailer;
$m->isSMTP();
$m->SMTPAuth=true;
$m->SMTPSecure = "tls";
$m->SMTPDebug=2;
$m->Host ="ssl:smtp.gmail.com:465";//my mail host
$m->Username='myusername@gmail.com';
$m->Password=##########;
$m->From='email@gmail.com';
$m->AddAddress("admin@mydomain.com");
$m->AddReplyTo('myusername@gmail.com'); // Reply TO
$m->FromName="{$firstname}";
$m->Subject='paper order';
$m->WordWrap = 50;
$m->isHTML(true);   
$m->Body="the details of the order are  firstname {$firstname} <br> lastname {$lastname}";
if(!$m->Send())
{
    echo "message could not be sent.<p>";
    echo"mailer error:" .$m->ErrorInfo;
    exit;
}
echo "Message has sent";


?
esqew
  • 42,425
  • 27
  • 92
  • 132
  • `$m->Host ="ssl:smtp.gmail.com:465";//my mail host` What's up with the `ssl:` you have in there? Is that even valid? – esqew Jun 20 '14 at 17:43
  • `->Host` is literally **JUST** the hostname. not this franken-string you're producing. – Marc B Jun 20 '14 at 17:43

1 Answers1

1

The official PHPMailer Gmail example declares the host as such:

$mail->Host = "smtp.gmail.com";

The port gets its own declaration as well:

$mail->Port = 587; 

I would assume that would be the cause of your SMTP connect() failed message.

esqew
  • 42,425
  • 27
  • 92
  • 132
  • it then brings the error SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP connect() failed. message could not be sent. mailer error:SMTP connect() failed. – user3743208 Jun 20 '14 at 17:49
  • That's a [different](http://stackoverflow.com/questions/6137304/phpmailer-could-not-connect-to-smtp-host) [error](http://stackoverflow.com/questions/8210099/php-php-network-getaddresses-getaddrinfo-failed-no-such-host-is-known). – esqew Jun 20 '14 at 17:51
  • that is after i do the corrections on the $m->host – user3743208 Jun 20 '14 at 17:53
  • Make sure you're also setting your `$m->port` variable, just like in the article I linked. Check my edit. – esqew Jun 20 '14 at 17:54
  • yes i have done that too – user3743208 Jun 20 '14 at 18:02
  • Check the links in my previous comment, they will be able to help you with that specific problem. – esqew Jun 20 '14 at 18:02