无论如何,在 php 或 cakephp 中,使用 smtp 发送电子邮件,以便我可以将电子邮件发送到封闭/内部邮件列表。例如:
在我的公司,我们有一个电子邮件列表:appsteam@company.com,只有当一个人也使用 xxx@company.com 电子邮件时才能发送。在该电子邮件之外,它将被阻止。所以在 cakephp 中无论如何都可以以某种方式获取用户凭据并在公司下发送电子邮件,或者在 gmail 电子邮件中发送电子邮件,如果它是谷歌组
我想我真正想要的是,如何设置 cakephp 电子邮件,以便它像我直接从电子邮件服务器发送一样发送,如果我使用 gmail,那么我希望它看起来像 gmail(标题等)
据推测,最终代码将做什么,我将从用户那里获取他们的电子邮件凭据,并使用它发送邮件。这是我的 AbcComponent.php 代码
/*
* Abc components
*/
class AbcComponent extends Component {
public $options = array();
/**
* Constructor
**/
public function __construct(ComponentCollection $collection, $options = array()){
parent::__construct($collection,$options);
$this->options = array_merge($this->options, $options);
}
public function send_link ($user_email = null, $recipients = null, $subject = null, $message = null, $group_id = null, $user_id = null, $email_id = null, $download_password = null) {
$final_subject = $subject;
$final_recipients = $recipients;
$final_message = $message;
App::uses('CakeEmail', 'Network/Email');
$recipients = str_replace(' ', '', $recipients);
$recipients = explode(',', $recipients);
$recipient_queue_num = 1;
//Send the email one by one
foreach ($recipients as $recipient) :
$email = new CakeEmail();
$email->delivery = 'smtp';
//$email->from($user_email);
$email->from('xxxxx@gmail.com');
$email->to($recipient);
$email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'xxxxx@gmail.com', //this will be later grab from dbase based on user
'password'=>'password',
);
$email->subject($final_subject);
$email->template('download_link_email');
$email->emailFormat('both');
$email->viewVars(array('final_message' => $final_message));
if($email->send()) {
debug('email is sent');
} else {
debug('email is not sent');
}
//queue number increase for hashing purpose
$recipient_queue_num++;
endforeach;
}