I have a problem in PHPMailer in particular. I have a contact form, and use PHPMailer to send emails. Apparently I can send, for me it returns "true", but the email does not arrive in your inbox. I've tried several ways to find the error, but without success. I tried enabling and disabling the SMTP with and without SMTP authentication, multiple forms. Follow my code below.
<?php
session_start();
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
//$mail->IsSMTP();
$mail->Host = "smtp.mysite.com";
$mail->SMTPAuth = false;
$mail->Username = 'my@email.com';
$mail->Password = 'passhere';
$mail->From = "Newsletter";
$mail->Subject = "Newsletter";
$email = $_POST['email_news'];
$mail->AddAddress('my@email.com');
$mail->IsHTML(true);
$mail->CharSet = 'utf-8';
$mail->Body = "
<html>
<body>
<b>Email:</b> $email<br/><br/>
</body>
</html>
";
if(!$email){
$result = "error";
}else{
$send = $mail->Send();
if($send){
$result = "sucess";
}else{
$result = "error";
echo $mail->ErrorInfo;
}
}
$mail->ClearAllRecipients();
$mail->ClearAttachments();
header("Location: http://www.mysite.com");
?>
I managed to solve my problem using authentication via gmail. Was as follows authentication:
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = 'my@email.com';
$mail->Password = 'passhere';
But I have a doubt. This authentication code is just for sending emails from gmail? Or is it an endorsement gmail provides for general validation email in PHPMailer?