I configured AWS SES as per this document.
Unable to send mail from a SES 'verified' email id (info#medicovibes.com)
If I run this code from an AWS EC2 instance, I get a blank page or 500 error. no error message pertaining to the problem can be seen.
<?php
// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
// Instantiate a new PHPMailer
$mail = new PHPMailer;
// Tell PHPMailer to use SMTP
$mail->isSMTP();
// Replace sender#example.com with your "From" address.
// This address must be verified with Amazon SES.
$mail->setFrom('info#medicovibes.com', 'rimo ');
// Replace recipient#example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
// Also note that you can include several addAddress() lines to send
// email to multiple recipients.
$mail->addAddress('support#dotweb.in', 'Vikas');
// Replace smtp_username with your Amazon SES SMTP user name.
$mail->Username = 'concealed';
// Replace smtp_password with your Amazon SES SMTP password.
$mail->Password = 'concealed';
// Specify a configuration set. If you do not want to use a configuration
// set, comment or remove the next line.
//$mail->addCustomHeader('X-SES-CONFIGURATION-SET', 'ConfigSet');
// If you're using Amazon SES in a region other than US West (Oregon),
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP
// endpoint in the appropriate region.
$mail->Host = 'email-smtp.us-east-1.amazonaws.com';
// The subject line of the email
$mail->Subject = 'Amazon SES test (SMTP interface accessed using PHP)';
// The HTML-formatted body of the email
$mail->Body = '<h1>Email Test</h1>
<p>This email was sent through the
Amazon SES SMTP
interface using the <a href="https://github.com/PHPMailer/PHPMailer">
PHPMailer</a> class.</p>';
// Tells PHPMailer to use SMTP authentication
$mail->SMTPAuth = true;
// Enable TLS encryption over port 587
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Tells PHPMailer to send HTML-formatted email
$mail->isHTML(true);
// The alternative email body; this is only displayed when a recipient
// opens the email in a non-HTML email client. The \r\n represents a
// line break.
$mail->AltBody = "Email Test\r\nThis email was sent through the
Amazon SES SMTP interface using the PHPMailer class.";
if(!$mail->send()) {
echo "Email not sent. " , $mail->ErrorInfo , PHP_EOL;
} else {
echo "Email sent!" , PHP_EOL;
}
?>
You can try to enable debug in PHP mailer and execute it from CLI.
php filename.php
https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging
You should be able to see where is the problem.
Related
In my case, In the Mailable Class I store the email in the variable hardcode form LIKE
$email = 'abc#example.com';
then, its work fine. but when we pass the email dynamically from the Controller LIKE
$this->email;
this shows the error are given below :
Expected response code 250 but got code "550", with message "550 The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements "
$subject = 'Account Created Successfully';
$name = 'Saakin Qatar';
return $this->view('emails.AgencyRegisterMail')
->from($address, $name)
->cc($address, $name)
->bcc($address, $name)
->replyTo($address, $name)
->subject($subject)
->with('inputs', $this->inputs);
It works but when I pass the address from the controller and store it like below:
$subject = 'Account Created Successfully';
$name = 'Saakin Qatar';
$name = 'Saakin Qatar';
return $this->view('emails.AgencyRegisterMail')
->from($address, $name)
->cc($address, $name)
->bcc($address, $name)
->replyTo($address, $name)
->subject($subject)
->with('inputs', $this->inputs);
then it returns the error
Twilio SendGrid developer evangelist here.
The error message here said:
Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements
On the page it recommends you visit it describes that to send emails you need to send them from either an email address that has been verified or an email address from an authenticated domain.
My guess is that you are building a contact form of sorts and trying to send the mail from an email address that a user enters into the form. If that is the case, you cannot use the user provided email address as the from parameter for sending the email, you have to use an email address that is verified or authenticated. But you can set the user's email address as the replyTo so that when you reply from your email client you write back to the user.
I have a situation where an app is sending its mails with PHPMailer and next configuration:
$mail->isSMTP();
$mail->Host = 'myhost.dev';
$mail->SMTPAuth = false;
$mail->setFrom($from, $from_name);
$mail->addAddress($to, $to_name);
if ($replyTo != '') $mail->addReplyTo($replyTo, $replyToName);
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $body;
As you can see, SMTP server doesn't require authentication and all is working ok. That's all data I have about the mail server. Now, I need to make the same thing but instead of using PHPMailer I want to implement the sending method of Laravel, but I don't have any authentication credential for setting my .env file.
How can I pass the same configuration to my Laravel development? I've tried many combinations but nothing happens. This was the last one:
MAIL_DRIVER=smtp
MAIL_HOST=myhost.dev
MAIL_PORT=25
MAIL_USERNAME=no-reply#host.com
MAIL_PASSWORD=''
MAIL_ENCRYPTION=''
PHPMailer has no idea about Laravel, so you need to pass through the information yourself. Laravel provides the env() global function to retrieve data from the environment, and you would use it like this:
$mail->Host = env('MAIL_HOST');
if (!empty(env('MAIL_USERNAME')) {
$mail->SMTPAuth = true;
$mail->Username = env('MAIL_USERNAME');
$mail->Password = env('MAIL_PASSWORD');
}
and so on, for any other configuration variables you need. I'm not sure exactly what Laravel package defines the env function, but you will need to make sure it's loaded and within scope before calling it.
I have a laravel app with a contact form. In local I was using mailtrap.io to test for emails being sent from the contact form and the emails were going through. I deployed my app and now when I submit a contact form, the user information gets stored in my database but the page re-directs and throws a 500 error. How do I send emails in a production enviornment? In local dev the page redirected back to my home and gave a flash message perfectly.
.env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=mailtrap-username
MAIL_PASSWORD=mailtrap-pw
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=myemail#gmail.com
MAIL_FROM_NAME="My Name Here"
Please follow these steps to send Email.
.Env
MAIL_DRIVER = smtp
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 587
MAIL_USERNAME = your-gmail-username
MAIL_PASSWORD = your-application-specific-password
MAIL_ENCRYPTION = tls
Send through Mail class with raw function.
\Mail::raw('Hi, welcome user!', function ($message) {
$message->to(..)
->subject(..)
->setBody('<h1>Hi, welcome user!</h1>', 'text/html');
});
Second way is send function:-
\Mail::send([], [], function ($message) {
$message->to('my#email.com')
->subject('my subject')
->setBody('Hi, welcome user!');
});
Hope It will work for you. Thanks!
Not working SMTP_validateEmail on live site using php
https://code.google.com/p/php-smtp-email-validation/
<?php
/**
* Example 1
* Validate a single Email via SMTP
*/
// include SMTP Email Validation Class
require_once('smtp_validateEmail.class.php');
// the email to validate
$email = $_POST['name'];
// an optional sender
$sender = $_POST['name'];
// instantiate the class
$SMTP_Validator = new SMTP_validateEmail();
// turn on debugging if you want to view the SMTP transaction
//$SMTP_Validator->debug = true;
// do the validation
$results = $SMTP_Validator->validate(array($email), $sender);
// send email?
if ($results[$email]) {
echo 1;
} else {
echo 0;
}
enter code here
?>
i am having problem on live site but it works fine in localhost.it shows the print_r($results) in the localhost but shows array(0) result in live.i also find $this->sock value in the class smtp_validateEmail.class function validate(email) value empty in live. how to solve this issue any help will be very thankful.
That "Add your web server ip address to var $nameservers = array(‘192.168.0.1’); and if your web server has Port number then update it here var $port = (Port number); Hope you will get the output by making this changes." Only work if you are sending mail with that script but cant tell if that mail checked is good one or not... I have been testing the code, try all changes, but still cant check other mails outside my domain. I can only make it work on my local and webserver host. Still cant call other servers to check if other mails from outside my domain are valid. Working on it.
Complete downloads are here for others to test : https://code.google.com/p/php-smtp-email-validation/downloads/list
Add your web server ip address to var $nameservers = array(‘192.168.0.1’);
and if your web server has Port number then update it here var $port = (Port number);
Hope you will get the output by making this changes.
My CakePHP should send an email when a button is clicked, however it doesn't. Also, the email will be displayed as a flash message if I run it in debug mode: ($this->Email->delivery = 'debug';).
Note: Email is set up to set up to use PHP mail() function.
Code to call the email function:
$this->_sendUpdateEmail( $this->Auth->user('id'), $about_id );
Email function
function _sendUpdateEmail($from_user_id, $about_id) {
$fromUser = $this->User->read(null, $from_user_id);
$users = $this->User->find('all', array(
'conditions' => array('User.distribution =' => 1)
));
# loop to send email to all users who are marked as on the distribution list
for($i = 0, $size = sizeof($users); $i < $size; ++$i) {
$user = $users[$i]['User'];
$this->Email->from = $fromUser['User']['email'];
$this->Email->replyTo = $fromUser['User']['email'];
$this->Email->to = $user['email'];
$this->Email->subject = 'Test email';
$this->Email->template = 'update';
$this->Email->sendAs = 'both'; // both = html and text
$this->set('user', $user);
$this->set('about', $about_id);
$this->Email->send();
$this->Email->reset();
}
}
Any ideas as to why the emails show in debug mode but won't actually send?
I think the reason why my emails were not sending was because there was no mail server configured on the web server my CakePHP was running on so there was no way to route the emails. However, this meant they would show up in the debug because they were generated successfully, just not sent.
In the end, I ended up using my company's Exchange mail server using the SMTP settings.
Code to use SMTP to send CakePHP emails
$this->Email->smtpOptions = array(
'port'=>'25',
'timeout'=>'30',
'host' => '192.168.0.244',
);
// Other email code here, e.g. from and to etc...
$this->Email->delivery = 'smtp';
I think the issue here is that mail server is not set right Linux comes built in with mail sending functionality but not windows (no idea on mac). look into smtp options as u can easily setup smtp email sender on Windows
Setting up smtp windows - http://publib.boulder.ibm.com/infocenter/cqhelp/v7r1m2/index.jsp?topic=/com.ibm.rational.clearquest.webadmin.doc/topics/c_config_email_smtp_win.htm
and
http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP