PHPmailer with AWS SES - php

I am trying to send emails through PHPmailer using the AWS SES SMTP account.
Somehow it sends emails when I ping the file from the terminal but fails to do so when I hit the same file from the browser. Below is the code.
$mail->isSMTP();
$mail->setFrom($sender, 'xx#site.com');
$mail->Username = USERNAME;
$mail->Password = PASSWORD;
$mail->Host = 'email-smtp.us-east-1.amazonaws.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 4;
$mail->SMTPSecure = 'tls';
$mail->addAddress('xx#gmail.com');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $bodyHtml;
$mail->AltBody = $bodyText;
$mail->Send();
The error in the browser says: SMTP Error: Could not connect to SMTP host.

Related

Office365 smtp not always working with php mailer

I'm trying to use office365 smtp with phpmailer, it authenticates and it delivers sometime but sometimes it does. Not in inbox or spam. It works well with other smtp server. Here is my code:
$mail = new PHPMailer(true);
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
$mail->CharSet = "utf-8";
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = $host;
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
//Provide username and password
$mail->Username = $user;
$mail->Password = $pass;
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "STARTTLS";
//Set TCP port to connect to
$mail->Port = $port;
$mail->From = $from_email;
$mail->FromName = $from_name;
foreach($recipients as $recipients){
$mail->AddBcc($recipients);
}
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->msgHTML($message);

How do I change the console log?

I use php to send email. It works perfectly, but I don't like that it outprints everything on the screen. I want this commant to remain silent. What should I do?
The command is the following:
verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '************#gmail.com'; // SMTP username
$mail->Password = '*********'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
//Recipients
$mail->setFrom('*********', 'Mailer');
$mail->addAddress('**************.com');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Want to get not';
$mail->Body = $_SESSION['nyelv'];
$mail->AltBody = $_POST['email1'];
$proba = $mail->send();

Getting SMTP Error "Could not connect to SMTP host" on server but working on my localhost

I am using phpmailer with gmail smtp, and its working for "tls" on my local xampp, but when i moved my project on server mail could not send and gives error: SMTP Error: Could not connect to SMTP host.
My Code is:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Port = 587; // Or 587
$mail->Username = $admin_email;
$mail->Password = $admin_password;
$mail->SMTPSecure = 'ssl';
$mail->From = $admin_email;
// $mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addAddress($emailTo);
if (!$mail->send()){
echo "error";
}
What is wrong in my code?

Email to SMS using PHPMailer

Good Day, I found in google that you can send sms messages just by typing the recipients mobile number plus the sms gateway using phpmailer and I tested it on my mobile phone but for some reason I don't received any sms messages. This is my php code:
require($_SERVER['DOCUMENT_ROOT']."/PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
// Configure smptp
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "**********#gmail.com";
$mail->Password = "******";
// Compose
$mail->Subject = "Testing";
$mail->Body = "Testing";
// Send to
$mail->AddAddress("***********#mysmart.mymobile.ph");
var_dump($mail->send()); //Send!
and here is the var_dump
I am residing in the philippines. Thanks.

PHPmailer : Showing a weird text before sending a mail?

My problem is clear, PHPmailer is howing a long text before sending a mail, this is my code (function) :
function sendMail($content){
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->Port=465; // Enable SMTP authentication
$mail->Username = 'my mail'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug=true;
$mail->From = '****';
$mail->FromName = '******';
$mail->addAddress('******');
$mail->Subject = 'subject';
$mail->Body=$content;
$mail->AltBody ='testing';
$stat=$mail->send();
}
and this is a screenshot :
http://i.imgur.com/kLrC97q.jpg
Thanks
Sorry guys, I noticed that I should turn off debugging :
$mail->SMTPDebug=false;

Categories