I am trying to send email in Yii using PHPMailer. I am working on a live server. Here is my Configuration for email in Yii's main.php:
'Smtpmail' => array(
'class' => 'application.extensions.smtpmail.PHPMailer',
'Mailer' => 'smtp',
'SMTPAuth' => true,
),
Here is the error I get:
The following From address failed: noreply#mywebsite.com : Called
Mail() without being connected
Here is my controller Code:
$mail->IsHTML(true);
$mail->From = Yii::app()->params['adminEmail'];
$mail->FromName = empty($_POST['EmailForm']["from_name"])
Yii::app()->params['emailFrom'] : $_POST['EmailForm']["from_name"];
$mail->Subject = $subject;
$mail->Body = nl2br($message) . $mail->Body;
$mail->AddAddress($to);
$mail->AddCC($cc);
if (!$mail->Send()) {
Yii::app()->user->setFlash('error', $mail->ErrorInfo);
$this->redirect(array('update', 'id' => $id));
}
else {
Yii::app()->user->setFlash('success', "Email sent successfully!");
$this->redirect(array('update', 'id' => $id));
}
Any help?
You're enabling auth but not providing an id or password, which doesn't seem likely to work. You're also setting the submitter's address as the from address, which is also likely to fail as it's a forgery that will fail SPF checks. Set your own address as the from address and put the submitter in a reply-to.
Beyond that, enable debug output (SMTPDebug = 2 in PHPMailer - I'm not sure how you set that from Yii) so you can see the SMTP conversation.
Related
Good morning,
I want to remove the gmail warning 'gmail couln't verify that ...#... sent this message' when I send email with php.
I know it is because I use the email function php that don't have authentification so I try PHPMailer and PHP pear but the page turn and turn until the infinite and nothing is happened.
My host is 1&1.
I try with gmail instead smtp and account instead of 1&1 but same result.
<?php
// Pear Mail Library
require_once "Mail.php";
$from = '<***#motelavigna.co>'; //change this to your email address
$to = '<***#gmail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'auth.smtp.1and1.fr',
'port' => '465',
'auth' => true,
'username' => '***#***.co', //co is not an error
'password' => '***' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
?>
thanks.
I came across this issue recently too and realised the problem is not from the PHP script, as I first thought, but from not having an SPF record for the domain name.
An SPF record identifies which mail servers are permitted to send emails from a particular domain name. If the domain doesn't have an SPF record then Gmail can't verify that the email came from the right place.
Coincidentally I'm also with 1&1, so see here for how to set up SPF records for 1&1. The value you need to use is:
v=spf1 include:_spf.perfora.net include:_spf.kundenserver.de -all
You can also check if the email passed the SPF test by clicking the arrow at the top of the email in Gmail, and pressing 'Show original'.
I'm going straight to the point here.
I'm trying to send an mail using codeigniter library.
However, I'm not receiving any email and there are no errors shown on my code.
I don't know why it doesn't work.
I've also followed the 2 step verification and allow access to less secure apps
However when I omit the config, it send me an email which goes directly to the spam section. I don't know why it goes to spam section.
Here's my code:
public function sending_email(){
// The mail sending protocol.
$config['protocol'] = 'smtp';
// SMTP Server Address for Gmail.
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
// SMTP Port - the port that you is required
$config['smtp_port'] = '465';
// SMTP Username like. (abc#gmail.com)
$config['smtp_user'] = 'sample#gmail.com';
// SMTP Password like (abc***##)
$config['smtp_pass'] = '****';
// Load email library and passing configured values to email library
$this->load->library('email', $config);
// Sender email address
$this->email->from('sample#gmail.com', 'sample');
// Receiver email address.for single email
$this->email->to('receiver#gmail.com');
//send multiple email
//$this->email->to(abc#gmail.com,xyz#gmail.com,jkl#gmail.com);
// Subject of email
$this->email->subject('test');
// Message in email
$this->email->message('hello world!');
// It returns boolean TRUE or FALSE based on success or failure
echo $this->email->send();
}
You can try this code also if commented link's answer is not working.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$result = $this->email->send();
I am using PHPMailer to send email. It works fine when I use gmail smtp but when I try using my domain smtp what I see on screen is 'message sent!' but I don't receive any email at all. I have tried using debugger, it says
We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
and here is my code
<?php
date_default_timezone_set('Etc/UTC');
//Load PHPMailer dependencies
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
/* CONFIGURATION */
$crendentials = array(
'email' => 'xxxxx#example.com',
'password' => 'xxxxxx'
);
$smtp = array(
'host' => 'secure.ehostpk.com',
'port' => 465,
'username' => $crendentials['email'],
'password' => $crendentials['password'],
'secure' => 'ssl' //SSL or TLS
);
/* TO, SUBJECT, CONTENT */
$to = 'xxxxxx#example.com'; //The 'To' field
$subject = 'This is a test email sent with PHPMailer';
$content = 'This is the HTML message body <b>in bold!</b>';
$mailer = new PHPMailer();
//SMTP Configuration
$mailer->isSMTP();
$mailer->SMTPDebug = 2;
$mailer->SMTPAuth = true; //We need to authenticate
$mailer->Host = $smtp['host'];
$mailer->Port = $smtp['port'];
$mailer->Username = $smtp['username'];
$mailer->Password = $smtp['password'];
$mailer->SMTPSecure = $smtp['secure'];
//Now, send mail :
//From - To :
$mailer->From = $crendentials['email'];
$mailer->FromName = 'Team'; //Optional
$mailer->addAddress($to); // Add a recipient
//Subject - Body :
$mailer->Subject = $subject;
$mailer->Body = $content;
$mailer->isHTML(true); //Mail body contains HTML tags
//Check if mail is sent :
if(!$mailer->send()) {
echo 'Error sending mail : ' . $mailer->ErrorInfo;
} else {
echo 'Message sent !';
}
I have searched a lot and I don't understand what should I do. Any help would be greatly appreciated.
One thing that I have found is, that on most servers these days (especially cpanel servers) the email address you are attempting to send with actually has to be created within cpanel itself in order for it to work properly.
From my understanding, the script only routes it to the server and the email account, and then it's routed further from there and finally sent out from your email account on the server. So a solution may be to actually setup the email address in your server.
I use PHPMailer for PHP5/6 and i try to make script witch will send mail and get error like "550 No Such User Here".
I read about DSN, and try tips from this How to set DSN (Delivery Status Notification) for PHPMailer? topic, but it's doesnt work.
(i found functin recipient where was
return $this->sendCommand(
'RCPT TO',
'RCPT TO:<' . $toaddr . '>',
array(250, 251)
);
)
and i try change link
'RCPT TO:<' . $toaddr . '>',
to
'RCPT TO:<' . $toaddr . '> NOTIFY=SUCCESS,FAILURE ORCPT=rfc822;' . $toaddr ."" .self::CRLF,
but i doesnt work.
I was try add it by function AddCustomHeader but it fail too.
This is my code:
private function send($username, $password, $from, $nameFrom, $replay, $subject, $email) {
try {
$_ = Zend_Registry::get('Zend_Translate');
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPKeepAlive = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->SetFrom($from, $nameFrom);
$mail->AddReplyTo($replay, $nameFrom);
$mail->Subject = $subject;
$mail->MsgHTML($this->_content);
$mail->AddAddress($email);
// $mail->AddCustomHeader( "X-Confirm-Reading-To: development.tabi#gmail.com" );
// $mail->AddCustomHeader( "NOTIFY=SUCCESS,FAILURE ORCPT=rfc822; $email" );
// $mail->AddCustomHeader( "Disposition-Notification-To: development.tabi#gmail.com" );
// $mail->AddCustomHeader( "Return-receipt-to: development.tabi#gmail.com" );
if (!$mail->Send()) {
return array(
'status' => false,
'message' => $mail->ErrorInfo
);
} else {
return array(
'status' => true,
'message' => $_->_('__MAIL_WAS_SEND__')
);
}
} catch (Exception $e) {
return array(
'status' => false,
'message' => $e->getMessage()
);
}
catch (phpmailerException $e) {
return array(
'status' => false,
'message' => $e->getMessage()
);
}
}
In result i have need script where:
When i write real address, ex my_real_addres#gmail.com it will be send,
but when i write fake address, ex my_fake_addres_which_not_exist#gmail.com will return me code 550, or any other error.
Is there any options to do this ? becouse i need to get and save all information.
Remember, that due to spambots and e-mail verifying scripts (such as yours). Many mail servers do not send those responses.
If they did, they would be flooded by spambots that would be asking for whole their mail databases (millions of records) if those e-mails exist.
For that reason, it's disabled on most mailservers nowdays.
Sources:
Is there a way to test if an E-Mail address exists without sending a test mail?
How to check if an email address exists without sending an email?
Edit:
Basically, every of those functions can be disabled by server admin. They may even return faked info etc. It's all to make it unsusable to spammers (legit uses got to suffer from this).
There are other methods to verify if e-mail exists. Ask for reply, for delivery confirmation etc.
Some servers when message could not be delivered return you e-mail. But that's not 100% sure behaviour, since spammers could spam servers with random generated e-mails and wait for returns.
Those measures are implemented to pervent spammers with brute-force mass e-mail checks.
They could run dictionary attack against google servers and quickly create list of all existing emails.
Don't know what you want achive, if you want to check if one of your newsletter subscribers deleted e-mail or grabbed e-mail from random site and want to confirm it.
You should follow one principle: All e-mails are unverified by default. You never know if its real or not unless it's been verified by recipent by clicking link, answering etc.
By me, there should be no status as "100% does not exist" since you're unable to verify it.
I created a contact form in my website, and, for send the e-mails to website account (contact#mywebsite.com), I'm using gmail smtp, using the same e-mail that I'll receive the messages.
So, users go to my website, click in contact page, fill the form with:
Name, Email, Message.
Than I send the email with the following code:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'contact#mywebsite.com',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$email = $this->input->post('email');
$name = $this->input->post('name');
$msg = $this->input->post('msg');
$this->email->to('contact#mywebsite.com');
$this->email->reply_to($email); //User email submited in form
$this->email->from($email, $name);
$this->email->subject('Conctact form');
$this->email->message($msg);
if ($this->email->send())
{
return true;
} else
{
echo $this->email->print_debugger();
return false;
}
The e-mail goes to my inbox in "contact#mywwebsite.com", I can read the message normally, but... when I click in "reply" instead of replying to the user that sent me the message, it replys to "me" (to contact#mywebsite.com).
I already configured the reply_to, to reply to users address, not mine, but still goes to contact#mywebsite.com.
How to fix this?
Should I change something more in the code or in gmail settings?
(PS.: I use gmail interface to read emails, directly from the site mail.google.com)
Thanks, in advance.
--
Also, when I receive the e-mail, It shows:
"From: 'Name in submitted form' "
Not:
"From: 'Name in submitted form' <'email in submitted form'>"
Like It should be.
Gmail does this, and I don't believe there is any sort of work around.
The "from" address will only ever be the account you are using to send the email - you cannot simply "pass through" gmail's server.
If you need to do that, you'll need something like SendGrid or your own smtp server
I fixed By sending the e-mail through another user ...
I sent from me#mywebsite.com to contact#mywebsite.com, and when I clicked in reply, the user selected was the same that sent the message in form.
GMail appearing to ignore Reply-To