简体   繁体   中英

Sending Email Via CakePHP - Configuration email override the sender email

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 .

    1. Click the Accounts and Import tab.
    2. Under Send mail as, click Add another email address .
    3. In the 'Email address' field, enter your name and alternate email address you own.
    4. Enter the SMTP server (eg 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).
    5. Click Add account >>
    6. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM