I am using Amazon ses account to send email.
All the credentials are working fine in core php with class.phpmailer.php
But not working with codeigniter email class on the same server
And not showing me any error with echo $this->email->print_debugger();
Please take a look at code
core php code
//include phpmailer
require_once('class.phpmailer.php');
//SMTP Settings
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "email-smtp.us-west-2.amazonaws.com";
$mail->Username = "AKIAIF4U4***5J36ROIA";
$mail->Password = "AhI9Nn********GSo4u8r0xNK/OI";
//
$mail->SetFrom('donotreply#*****.com', 'medi***'); //from (verified email address)
$mail->Subject = "Email Subject"; //subject
//message
$body = "This is a test message vipul.";
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
//recipient
$mail->AddAddress("vipul.kumar#******.com", "Test Recipient");
//Success
if ($mail->Send()) {
echo "Message sent!"; die;
}
//Error
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
codeigniter code
public function test_aws_email($data=array()){
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'tls://email-smtp.us-west-2.amazonaws.com',
'smtp_port' => 465,
'smtp_user' => 'AKIAIF4U4***5J36ROIA',
'smtp_pass' => 'AhI9Nn********GSo4u8r0xNK/OI'
);
$config['crlf'] = "\r\n";
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from("donotreply#******.com", 'Medi***');
$this->email->to('vipul.kumar#******.com');
$this->email->subject('TEST FOR AWS ');
$this->email->message('AWS AUTHENTICATION CLEAR ');
$this->email->set_mailtype("html");
$this->email->send();
echo $this->email->print_debugger();
}
Related
On one of of my GoDaddy servers, the PHPMailer does NOT work. While the same script does work pretty fine on local as well as on another GoDaddy server.
I'm using following script:
<?php
$to = "username#gmail.com";
$subject = "Test Subject";
$message = "Test email message";
require("PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->SMTPDebug = 3;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->SMTPOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => false
)
);
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "username#gmail.com";
$mail->Password = "password";
$mail->SetFrom("username#gmail.com", "Website Admin");
$mail->AddAddress($to, "Website Admin");
$mail->Subject = $subject;
$mail->Body = "<html><body style='font-family:Arial, Helvetica, sans-serif;'>";
$mail->Body .= "<table>";
$mail->Body .= "<tr><th>Email:</th><td>$to</td></tr>";
$mail->Body .= "<tr><th>Message:</th><td>$message</td></tr>";
$mail->Body .= "</table>";
$mail->Body .= "</body></html>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients.";
$mail->WordWrap = 70;
if($mail->Send())
{
echo "Mail sent";
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
It gives me following error on GoDaddy:
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I'm using PHPMailer version 5.2.27.
I'm using app password for gmail account.
If the script was buggy then how it could even work in another areas? How to fix it to work on that GoDaddy server too?
I have already tried their host and port various combination and some other settings too.
I can't understand why this question is negatively marked. The people doing this could not even imagine that there could be some other potentially valid reason behind this issue.
Anyway, I've solved this issue on my own. SMTP services are not enabled by default on VPS, but only on dedicated servers. I enabled them and my PHPMailer is working.
Thanks to everyone here for helping me.
I'm trying to sending an email using CodeIgniter via Gmail SMTP but the function is not working it is showing me this error on the localhost?
An Error Was Encountered Unable to send email using PHP mail().
Your server might not be configured to send mail using this method.
Here my email function
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '******#gmail.com', // change it to yours
'smtp_pass' => '**********', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = 'Test';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('*********#gmail.com'); // change it to yours
$this->email->to('test#gmail.com');// change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
Use PHP MAILER or SWIFT MAILER
https://github.com/PHPMailer/PHPMailer
https://github.com/swiftmailer/swiftmailer
For now here is PHPMAILER
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
//$mail->Host = gethostbyname('smtp.gmail.com');
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'sender#gmail.com'; //SMTP username
$mail->Password = 'sender-password'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('receiver1#gmail.com', 'Mailer');
$mail->addAddress('receiver2#gmail.com', 'Dylan');
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
You can install these amazing libarries with composer
I am using php mailer to send mail. It is working on localhost. But not working on live cpanel hosting.
Mail is sending proper in my localhost. In live server I found error.
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
public function send_mail($to,$bodytext,$subject)
{
try{
// start mailer
$toAddress = $to;
$message = $bodytext;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->IsHTML(true);
$mail->Username = "xxxxxx#gmail.com"; // your gmail address
$mail->Password = "xxxxx#123"; // password
$mail->SetFrom("xxxxxx#gmail.com");
$mail->Subject = $subject; // Mail subject
$mail->Body = $message;
$mail->AddAddress($toAddress);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
return False;
} else {
return true;
}
// end mailer
}
catch (Exception $e)
{
return $e->getMessage();
}
}
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->Username = "my gmail email id";
$mail->Password = "my gmail password";
$mail->IsHTML(true);
$mail->From = "sender#gmail.com";
$mail->FromName = "Sender name";
$mail->addAddress("receiver#gmail.com","Receiver");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
Executing this script shows : PHPMailer Error: SMTP connect() failed.
1. php_openssl and php_smtp extensions are enabled.
2. IMAP is enabled in GMAIL SETTINGS
turn on less secure app in your google account setting..
ref:: https://support.google.com/mail/answer/7126229
This Code is working for me
$sender_email='test#gmail.com';
$receiver_email='test#gamil.com';
$username='username';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'test#gmail.com';
$config['smtp_pass'] = '#####';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Sender email address
$this->email->from($sender_email, $username);
// Receiver email address
$this->email->to($receiver_email);
// Subject of email
$this->email->subject('Testing');
// Message in email
$this->email->message('this is testing mail');
$this->email->send();
This is my php code to send a confirmation email to a new user and the problem is, i am not receiving it(i have tried different ones, no luck)
function send_email($info)
{
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Welcome to Site Name');
$message ->setFrom(array('noreply#localhost' => 'localhost'));
$message ->setTo(array($info['email'] => $info['username']));
$message ->setBody($body_plain_txt);
$message ->addPart($body, 'text/html');
$result = $mailer->send($message);
return $result;
}
I get no errors
Install phpmailer.
Here is a sample on how to send mail with PHP mailer
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
If your destination address is #hotmail.com it may never income because they have a strong anti-spam management.