Sending Email Via CakePHP - Configuration email override the sender email - cakephp

I am having problem on sending email via cake php 2.7. Well, the email gets forwarded to the desired email address but there is problem in getting sender email address, as I am getting configuration email address in the place of sender email address. I have problem in getting how to fix this issue. It would be grateful if anybody could suggest anything regarding the issue.
Some parts of code are:
pages controller
public function sendEmail($data) {
$email = new CakeEmail();
$email->config('gmail');
$email->emailFormat('html');
$email->sender($data['User']['email_address'],$data['User']['name']);
$email->from(array($data['User']['email_address'] => $data['User']['name']));
$email->to('configuration_email');
$email->replyTo($data['User']['email_address']);
$email->subject($data['User']['subject']);
$message = 'Name: '.$data['User']['name'].'<br> How Did You Hear: '. $data['User']['how_did_you_hear'].
'<br>Message: '.$data['User']['body'];
if ($email->send($message))
{
return true;
}else {
return false;
}
}
email.php
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'configuration_email',
'password' => 'password',
'transport' => 'Smtp'
);
'From' field is using configuration email instead of using $data['User']['email'].
Thank you in advance!

Gmail lets you send messages on behalf of an email address different from your Gmail address only if you already own that email account and it is properly registered in your Gmail account.
Instructions are described in Gmail: Send mail from a different address or alias:
I'm a Gmail or Google Apps user sending from an external address.
Click the gear in the top right .
Select Settings.
Click the Accounts and Import tab.
Under Send mail as, click Add another email address.
In the 'Email address' field, enter your name and alternate email address you own.
Enter the SMTP server (e.g. smtp.domain.com), your username on that domain, and your password for that account. You may also need to adjust your port setting or SSL setting (talk to your other ISP if you need this information).
Click Add account >>
Open your other account and either click the link in the message Gmail sent or enter the confirmation code in the Accounts and Import section of your Gmail settings.
If Gmail sent a verification email and you didn’t receive it, try checking your Spam or Bulk Mail folders for a message from account-verification-noreply#google.com to see if the email ended up in there.

Related

CakePHP 3 - How to check whether an Email has been delivered successfully?

i am trying to sending mail using cakephp 3.0 .
My code is :
Email::configTransport('WebMail',[
'className' => 'Smtp',
'host' => $host,
'port' => $port,
'timeout' => 30,
'username' => $username,
'password' => $password,
'client' => null,
'tls' => null]
);
$transport = ['transport' => 'WebMail'];
$email = new Email($transport);
$email
->from([$username => $senderName])
->to($email_to)
->subject('Password Reset Code');
$response = $email->send('hello');
its working fine but the problem is how to check if the email was delivered successfully or not to the recipient.
if I debug $response variable I got the array of all mail related data.
Now how can I check if the email was delivered or not .
You can't... at least not reliably. All CakePHP can tell you is whether sending/queing the mail was successful, and depending on the transport (Smtp/Mail/...) that you're using you can get the last response received from the E-Mail server.
If sending/queing was unsuccessful, a \Cake\Network\Exception\SocketException exception will be thrown, so catch that if you want to evaluate this problem. Other than that there's no further information CakePHP/PHP can provide you with.
try {
$email->send();
} catch (\Cake\Network\Exception\SocketException $exception) {
// sending/queing failed
// the last response is available when using the Smtp transport
$lastResponse = $email->transport()->getLastResponse();
}
If applicable you could use a custom Smtp transport and implement requesting DSNs (Delivery status notifications, which you could then evaluate later on, however this isn't foolproof either, as notifications aren't guaranteed.
See also
API > \Cake\Mailer\Transport\SmtpTransport::getLastResponse()
API > \Cake\Mailer\Email::transport()
You'll need to add some form of tracking pixel to the email, or just use a transactional email service like Mandrill (MailChimp) or SendGrid...etc that will do this for you. You can then see whether they received it, and if they opened it...etc.
You can manually open the inbox of sending email to check if the mail was sent. If due to any reason the mail could not be sent, you'll receive a revert mail stating the problem.
Now, I know this is not a very efficient method so you need to keep these things in mind :-
1. You need to lower the security of your email.
2. You should not send codes (JavaScript etc) on email.
3. Keep in mind the size of content you are sending.
With these points checked you can assume your mail was sent. For a safer side you can check you mail once a week/month to see if all the mails were sent or if you got any error.

Email is not going to deliever on yahoo server

I am using cakephp, and sending email through cakeemail with smtp. My hosting is on 1and1.com. Email is going to deliver on gmail but not on yahoo and hotmail.
Then I try the PHPMailer on same server and its email was going to deliver on gmail and hotmail as well. But unfortunatly I am unable to use PHPMailer with cakephp. I have try two tutorial but fails. One of them is here.
I will prefer to fix the problem with cakeemail, if some one can help regarding this.
Or if can get solution with PHPMailer for cakephp that is also ok.
Here is the my code
$email = new CakeEmail();
$email->smtp = array(
'port'=>'25',
'timeout'=>'30',
'host' => 'smtp.1and1.com',
'username'=>'quote#xxxxxx.com',
'password'=>'xxxxxx_',
'client' => 'smtp.1and1.com' ,
'transport' => 'Smtp'
);
$email->from(array('xxxx#a-xxxx.com' => 'A-Best Auto Parts Quote'));
$email->to("xxxx#yyy.com");
//$email->bcc("xxxx#yyy.com");
$email->subject('My Test Subject');
$email->emailFormat('html');
$body="the test message for email"
$email->send($body);

Sending Activation Email , SMTP server did not accept the password

I'm sending an email using CakePHP and I got an Error: SMTP server did not accept the password, along with an email in my inbox says that: sign-in attempt blocked! , we recently blocked a sign-in attempt to your Google Account.
Is that normal?
I'm using Xampp.
function sendActivationEmail($user_id)
{
Debugger::dump($user_id);
$user = $this->User->findById($user_id);
if ($user==false)
{
debug(__METHOD__." failed to retrieve User data for user.id: {$user_id}");
return false;
}
$this->set('username', $this->data['User']['username']);
$this->Email->to = $user['User']['email'];
$this->Email->subject = env('SERVER_NAME').'- Please confirm your email address';
$this->Email->from = 'laurent#gmail.com';
$this->Email->template = 'account_verification';
$this->Email->delivery = 'smtp';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'laurent#gmail.com',
'password'=>1234567
);
$this->Email->sendAs = 'text';
return $this->Email->send();
}
You need to allow "less secure" apps in your Google account settings:
https://www.google.com/settings/security/lesssecureapps
See this announcement as well http://googleonlinesecurity.blogspot.de/2014/04/new-security-measures-will-affect-older.html
You should implement OAuth2 instead of weakening the security!
Make sure that the field in 'username' => and 'password'=> is authenticate or valid. I had experienced the same issue and all I do is to go this link https://accounts.google.com/b/0/DisplayUnlockCaptcha and click the button 'Continue'.
make sure you're logged in in gmail using the 'username' and 'password' provided in your code. After that, try to send email again.
I was facing same issue. in my case Password was not so strong. It contains username in password. I change the password and try again. it works.
*The other thing you can do that you can use other email address with strong password. make sure captcha is and less secure is enabled. *
https://accounts.google.com/b/0/DisplayUnlockCaptcha

Cakephp email sending email with "via" near to sender email id

Im fed up with this problem, tried all the things and measures but the problem remains. Whenever im sending an Email using cakephp 2.x im getting a "via" xyzabc.com , near to the sender's email id in email inbox.
Here is my code -
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from('noreply#'.env('SERVER_NAME'));
$Email->replyTo('noreply#'.env('SERVER_NAME'));
$Email->sender('noreply#'.env('SERVER_NAME'));
$Email->to('myemailid#gmail.com');
$Email->subject('Account activation Link');
$username="Katrina";
$link="http://mywebsite.com/users/account_activation/myemailid#gmail.com/jkasjfi3ed34";
$Email->viewVars(array('user_name' => $username,'link'=>$link));
$Email->template("user/new_user_registered");
$Email->emailFormat("html");
$Email->send();
Please help with the issue, what is wrong with my code?

How do I send email from Google App Engine with a random, non-app admin sender?

Google App Engine has a rule of only allowing app admins to send email.
Is there a workaround that anyone out there is using to send emails from non-admin addresses?
I'm building a B2B white-label platform, and being able to mask the "FROM" address is very important without giving my customers admin access.
The docs also state:
Any valid email receiving address for the app (such as xxx#APP-ID.appspotmail.com).
So you can make up an sender address based on that, and even correctly route that email back into your app if anyone replies to it.
It is also possible to send email on behalf of a logged in user, assuming that user is using a Google Account.
user = users.get_current_user()
message = mail.EmailMessage(sender=user.email())
#Set other message components, such as message.body
try:
message.send()
except:
message.sender = #An APP-ID.appspotmail.com address, or Admin address
message.send()
If you need the email to appear as if it was sent by a user and when replied to reply back to that user's actual email address then you can make use of reply_to.
user_name = 'Some Guy'
user_email = 'some.guy#whatever.com'
admin_email = 'no-reply#yourdomain.com'
from_email = '%s <%s>' % (user_name, admin_email)
reply_to = '%s <%s>' % (user_name, user_email)
mail.send_mail(from_email, to_email, subject, body, reply_to=reply_to)
This way to the person receiving the email it will appear that it came from user_name and if they reply then their reply email will be sent to user_email.
The main negative of this approach is that if someone looks closely at the address they received the message from they will see the admin email address but most email clients show the name more prominently.
On the plus side you can send as any email address and most people would never notice it came from an admin email address.

Resources