Integrating PHPmailer with Ec2 - amazon-ec2

Hello I have this code to send mail but mail is not getting sent. I can not send mail from the online server but I can send mail locally. What could be the issue?
$mail = new \Core\mailer\Phpmailer();
$mail->IsSMTP(); // we are going to use SMTP
$mail->SMTPAuth = true; // enabled SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "email-smtp.eu-west-1.amazonaws.com";
$mail->Port = 587; // SMTP port to connect to GMail
$mail->Username = "******"; // user email address
$mail->Password = "*********"; // password in GMail
$mail->SetFrom('upload#irokingdev.com', 'IROKING'); //Who is sending the email
$mail->AddReplyTo('upload#irokingdev.com', 'iROKING Registration');
$mail->Subject = 'Registration on iROKING';
$mail->Body = $body;
$mail->AltBody = "Plain text message";
$destination = $to; // Who is addressed the email to
$mail->AddAddress($destination, "");
if(!$mail->Send()) {
echo "Error: " . $mail->ErrorInfo;
} else {
echo "Message sent correctly!";
}

I'm gonna take a stab at and say that you are probably missing your email address upload#irokingdev.com as a verified email address in Amazon SES.
You can do it from AWS SES console:

Related

can't sending smtp emails with codeigniter

my codeigniter framework wont send emails by smtp. I always return a error that he cannot send the my by smtp over php on this server. If i check my username, host and password by copy and past to login with a webclient into the mailbox, it workds. So i use the correct host, username and password.
I think i have setup something wrong, but i dont know what.
Thats the email_helper
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = $settings['smtp_host']; (smtp.domain.com)
$config['smtp_port'] = $settings['smtp_port']; (465)
$config['smtp_timeout'] = '30';
$config['smtp_user'] = $settings['smtp_user']; (email = user)
$config['smtp_pass'] = $settings['smtp_pass']; (my password)
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$controller->load->library('email');
$controller->email->initialize($config);
$controller->email->from( $settings['email_from'] , $settings['application_name'] );
$controller->email->to($to);
$controller->email->subject($subject);
$controller->email->message($body);
if($cc != '')
{
$controller->email->cc($cc);
}
if($attachment != '')
{
$controller->email->attach(base_url()."your_file_path/" .$attachment);
}
if($controller->email->send()){
return "success";
}
else
{
echo $controller->email->print_debugger();
}
}
I've chekced the correct values from the $settings array, too.
To send the email i do it in this way
$this->mailer->mail_template($to,'forget-password',$mail_data);
Adding the ssl information solved the problem
$config['smtp_crypto'] = 'ssl';

Send email using SMTP without Username & Password

I am trying to send an email using SMTP without username & password as below:
var $smtp_host = "*****"; // SMTP Server.
var $smtp_user = ""; // SMTP Username
var $smtp_pass = ''; // SMTP Password
var $smtp_port = "443"; // SMTP Port 25, 587
So is it possible to send email with this config setting?
You will always need username and password.
please read about smtp...
PHPmailer would be helpful if your using codeigniter
https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

PHPMailer didn't work in Windows Server 2012 - Unable to relay w/Gmail, Yahoo, etc ...

I have a problem with PHPMailer inside my Windows Server 2012. I'm using XAMPP as my local server. I notice that i cannot ping smtp.gmail.com in my window server 2012. it says
ping request could not find host smtp.gmail.com. Please check and try again
I added this line in php.ini
[mail function]
smtp_server=smtp.gmail.com
smtp_port=25
sendmail_path ="\"D:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=On
And I added this line in sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=example#gmail.com
auth_password=password
force_sender=
force_recipient=
hostname=localhost
I test my PHPMailer in my local PC, it works fine. I can send into my own domain email ("example#pn.com") and other domain email such as test#gmail.com, test#yahoo.com etc. Here's my PHPMailer code.
testsend.php
<?php
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "example#gmail.com";
$mail->Password = "password";
$mail->setFrom('test#gmail.com', 'First Last');
//$mail->addReplyTo('replyto#example.com', 'First Last');
$mail->addAddress('test#gmail.com', 'John Doe');
$mail->Subject = 'PHPMailer GMail SMTP test';
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->Body = 'dfssf';
$mail->AltBody = 'This is a plain-text message body';
//$mail->addAttachment('images/phpmailer_mini.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
But when I add similar PHPMailer folder and files inside my server, it only work when I send to my own domain which is ("example#pn.com").It does not work with other email domain such as gmail, yahoo etc. It says
Mailer Error: SMTP Error: The following recipients failed: test#gmail.com: Unable to relay
How to fix that problem ?
Thanks.

Error while sending email in codeigniter

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp_host';
$config['smtp_port'] = 25;
$config['smtp_user'] = 'smtp_user';
$config['smtp_pass'] = '$$$';
$this->load->library('email', $config);
$this->email->initialize($config);
$this->email->from($config['smtp_user']);
$this->email->to('aaaa#test.com');
$this->email->subject('TEST MAIL');
$this->email->message('TESTING OF MAIL');
if ($this->email->send()) {
return true;
} else {
return false;
}
This is my code for sending email. I got below error.
Message: fsockopen(): unable to connect to box334.bluehost.com:25 (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. )
You email server is not responding properly. try to check your email server setting like smtp PORT, SMTP HOST and USER etc.

Codeigniter PHPMailer email not sending to office 365 account

i am using php mailer in Codeigniter.
here is my email settings
mail was sending to other email id but not sending to email id which is in office 365.
<?php defined('BASEPATH') OR exit('No direct script access allowed.');
$config['useragent'] = 'PHPMailer'; // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'example#example.com';
$config['smtp_pass'] = 'password';
//$config['smtp_port'] = 587;
$config['smtp_timeout'] = 5; // (in seconds)
$config['smtp_crypto'] = 'tls'; // '' or 'tls' or 'ssl'
$config['smtp_debug'] = 4; // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['wordwrap'] = true;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html'; // 'text' or 'html'
$config['charset'] = 'ISO-8859-15'; // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.
$config['validate'] = true;
$config['priority'] = 3; // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see https://github.com/PHPMailer/PHPMailer/issues/449
$config['crlf'] = "\n"; // "\r\n" or "\n" or "\r"
$config['newline'] = "\n"; // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode'] = false;
$config['bcc_batch_size'] = 200;
$config['encoding'] = '8bit'; // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.
i have the following error
Connection: opening to smtp.office365.com:25, timeout=5, options=array ( ) 2016-01-02 10:00:49 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-01-02 10:00:49 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting bool(false)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
same setting are working in other servers, but not working in Go daddy server.
i checked openssl connection was enabled.
There are many duplicates of this question, and it's also covered in the PHPMailer docs: GoDaddy blocks outbound email, so you have to use their mail servers.

Resources