gpt4 book ai didi

php - 如何在 zf2 中使用 smtp 发送电子邮件?

转载 作者:行者123 更新时间:2023-12-02 06:34:21 26 4
gpt4 key购买 nike

<分区>

我做了一个 zf2 操作,其中我想向保存在数据库中的用户发送电子邮件,所以我使用 gmail 发送电子邮件但电子邮件没有发送给用户。

我如何在 zf2 中发送电子邮件?

这是我的代码:

public function addAction()
{
//check permissions
if(!$this->acl->isAllowed($this->user->user_type, 'user.create'))
$this->redirect()->toRoute('admin_index');
//
$this->layout()->top_heading = 'Add User';
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
////////////////////////////////
$form = new UserForm();
$update=false;
$message='';
if($this->getRequest()->isPost())
{
$post = $this->getRequest()->getPost();
$form->setInputFilter($form->getInputFilter());
$form->setData($post);
if($form->isValid())
{
$formData=$form->getData();
$s = new User();
$user = $dm->getRepository('Calendar\Document\User')->findOneBy(array(
"username" => $formData['username']
));
$email = $dm->getRepository('Calendar\Document\User')->findOneBy(array(
"email" => $formData['email']
));
if($user || $email)
{
$update=2;
$message='User Already Exists.';
}
if($post['role']=='admin')
{
$update=2;
$message="Select Some Other Role.";
}
else
{
$s->setProperty('username',$post['username']);
$s->setProperty('password',md5($post['password']));
$s->setProperty('email',$post['email']);
$s->setProperty('user_type',$post['role']);
$s->setProperty('dataentered',date('Y-m-d H:m:i'));
$dm->persist($s);
$dm->flush();
//echo new Response($s->getProperty('id'));
//
$update=1;
$message='User Added Successfully.';
$form = new UserForm();
$config = array('ssl' => 'tls',
'auth' => 'login',
'username' => 'marif252@gmail.com',
'password' => 'password');

$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail();
$mail->setBodyHtml($bodytext);
$mail->setFrom('marif252@gmail.com');
$mail->addTo($formData['email'], $formData['username']);
$mail->setSubject('Profile Activation');
$mail->send($transport);

如何在 zf2 中使用 gmail 发送电子邮件?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com