I've got a problem with email sending in cake. My method looks like this:
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'mymail#gmail.com',
'password'=>'mypass',
);
$this->Email->from = "admin#localhost";
$this->Email->to = "my_test_mail#centrum.cz";
$this->Email->subject = "Test";
$this->Email->sendAs = "text";
$this->Email->delivery = 'smtp';
$this->Email->send('Hello message body!');
But when I try to send the email I get:
555 5.5.2 Syntax error. l3sm512374fan.0
What do I need to chnage in order for this to work?
Thanks
Per RFC2821, to which Google's SMTP servers seem to be a stickler on, the format of the email addresses should be in the following way:
Recipient Name <myname#example.com>
-or-
<myname#example.com>
Do this for both the from and to address, and you should be good to go. If you don't have the name of the user, then you can just repeat the email:
$this->Email->to = "my_test_mail#centrum.cz <my_test_mail#centrum.cz>";
-or-
$this->Email->to = "<my_test_mail#centrum.cz>";
Related
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.
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 am looking into cakephp email component first time. I am sending email like this from my localhost:
$this->Email->smtpOptions = array( 'port'=>'465',
'timeout'=>'30',
'host'=>'smtp.gmail.com',
'username'=>'mygmail#gmail.com',
'password'=>'mygmailpassword'
);
$this->Email->delivery = 'smtp';
$this->Email->from = "mygmail#gmail.com";
$this->Email->to = "yourgmail#gmail.com";
$this->Email->subject = "Subject";
$this->Email->sendAs = 'html';
$this->Email->lineLength = 255;
$body = "<h1>This is body</h1>";
$this->Email->send( $body );
It is not sending any email or not even showing any error.
Is there something missing ?
Thanks
Gmail's SMTP server requires SSL if I recall correctly.
Try
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'your_username#gmail.com',
'password'=>'your_gmail_password',
);
Host should be : ssl://smtp.gmail.com
Do you know if it is posible to set a DSN communication using the Pear Mail function in PHP?
Explain:
If a write this code in a telnet session:
telnet smtp.example.com 25
[...]
mail from: me#example.com
250 2.1.0 Ok
rcpt to: you#fakemail.com NOTIFY=SUCCESS,FAILURE,DELAY ORCPT=rfc822;you#fakemail.com
250 2.1.5 Ok
[]
i received a notification mail with a status code from the receiver smtp server (relayed, failed, etc.) when my smpt server sends the email. Now i want to do the same using Pear Mail, but I can't find where i have tu put this option.
This is my code:
$messageTEXT= "..." // text_message
$messageHTML="..." // html message
$headers=array();
$headers['From'] = "me#example.com";
$headers['To'] = "you#fakemail.com";
$headers['Subject'] = "Test mail";
$headers['X-Mailer']="My PHP mailer";
$headers['X-Priority']=3;
$headers['Errors-To'] = "me#example.com";
$headers['Return-Path'] = "me#example.com";
$headers['Disposition-Notification-To'] = "me#example.com";
$message = new Mail_mime();
$message->setTXTBody($messageTEXT);
$message->setHTMLBody($messageHTML);
$mimeparams=array();
$mimeparams['charset']= "UTF-8";
$mimeparams['text_encoding']="8bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$body = $message->get($mimeparams);
$headers = $message->headers($headers);
$smtp = Mail::factory(
'smtp',
array(
'host' => "smtp.example.com",
'port' => "25",
'auth' => true,
'username' => "myuser",
'password' => "mypass")
);
$mail=$smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
print ("Error");
return false;
}
http://pear.php.net/manual/en/package.mail.mail.php
You will have to hack PEAR::Mail and Net::SMTP a bit to get this to work.
The standard Mail_smtp::send() method calls into Mail_RFC822::parseAddressList() which will reject the extra data. Commenting out those lines (around line 274) should get you started.
Then you'll need to hack Net_SMTP::rcptTo() to pass the raw data rather than wrapping it in angle brackets.
Make sure your data is being sanitized somewhere else if you're going to circumvent those methods.
FIrst of all I don't intend to spam - I 'm building email facility in my application and would like to be able to include any email address in the from header of the email while be able to send it from any mail server i.e like show a yahoo address in the email from field while send it from my own smtp server? Is it possible? I'm using php and zend framework here
Zend_Mail allows you to specify all that.
Setting up transport (during bootstrap):
$tr = new Zend_Mail_Transport_Smtp($mail_smtp_host, array(
'auth' => 'login',
'username' => $mail_smtp_username,
'password' => $mail_smtp_password,
'port' => $mail_smtp_host_port,
));
Zend_Mail::setDefaultTransport($tr);
Sending a message anywhere in your app:
$mail = new Zend_Mail();
$mail->setFrom($email_from, $email_from_name)
->addTo($email_to)
->addCc($email_cc)
->addBcc($email_bcc)
->setSubject($email_subject)
->setBodyHtml($email_html)
->setBodyText($email_text)
->send()
;
The following works with sendmail and should work with sendmail-like smtp servers. If the from domain does not match the domain of the originating server, the chance of being flagged as spam increases.
$msg = 'my message body';
$subject = 'my message';
$to = 'email#example.com';
$from = "ali#yahoo.com";
$headers .= "From: $from\r\n";
$flags = '-f "$from"';
mail($to, $subject, $msg, $headers, $flags);
You can send through Yahoo's SMTP server.
smtp.mail.yahoo.com, SSL, port 465, username/password for the Yahoo address.