0

I want to send an email with PHPMailer class to my email address(ramin.badri69@gmail.com) This is my code:

<?php
require_once('class.phpmailer.php');
require_once('class.smtp.php');
require_once('PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->addAddress('ramin.badri69@gmail.com');
$mail->setFrom('asbd@gmail.com','ramin');
$mail->addReplyTo('asd@gmail.com');
$mail->Subject ='HI';
$mail->Body ='<h2>Hello World!</h2>';
$mail->isHTML(true);
$mail->isSMTP();
$mail->SMTPAuth =true;
$mail->SMTPSecure='ssl';
$mail->Host ='ssl://smtp.gmail.com';
$mail->Port=456;
$mail->Username='farzin.badri@gmail.com';
$mail->Password='*****';
if($mail->send()){
    echo "<h3>message sent.</h3>";
}else{
    echo "<h3>Error</h3>";
}

But I see "ERROR" every time I run it. Both "ramin.badri" and "farzin.badri" are valid email addresses. I have downloaded PHPMailer class already and attached it to the current PHP script as you can see above. Help me on this code,I cant see any new email in the my inbox(ramin.badri69@gmail.com is my email).

ramin_b
  • 63
  • 6
  • use the debug feature and check for errors. `echo "

    Error

    ";` doesn't do much to help you
    – Funk Forty Niner Jul 21 '15 at 15:45
  • do u think that this should normally work?don't u see any issue? – ramin_b Jul 21 '15 at 15:50
  • Use either `$mail->SMTPDebug = 1;` or `$mail->SMTPDebug = 2;` and add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Jul 21 '15 at 15:56
  • I did what u told and this was the error: 2015-07-21 16:14:52 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) 2015-07-21 16:14:52 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting – ramin_b Jul 21 '15 at 16:16

1 Answers1

0

I found the problem...in my PHP page,I wrote $mail->port instead of $mail->Port! But here in the stackOverflow I wrote with upper-case word! So,be careful of such a tiny hidden problem in your PHP projects,all attributes should begin with upper-case words and in all methods you should observe camel-notation.

ramin_b
  • 63
  • 6