Sending email via SMTP on zend framework

2019-01-20 04:53发布

问题:

$config = array('auth' => 'login',
                'username' => '****@gmail.com',
                'password' => '****',
                'port' => '25',
                'ssl' => 'tls');


$transport = new Zend_Mail_Transport_Smtp('smtp.googlemail.com', $config);

what should i do after that, where can i put the body and the recipient address.

回答1:

Its described in the manual of Zendframework

Zend_Mail::setDefaultTransport($transport);

Then somewhere else instanciate Zend_Mail, write your mail and send it.



回答2:

See the documentation for full examples (although the Zend docs admittedly often aren't great).

Based on a comment here:

$mail = new Zend_Mail();
$tr = new Zend_Mail_Transport_Smtp(...);
$mail->setFrom('...', 'Server');
$mail->addTo($to, '....');
$mail->setSubject($subject);
$mail->send();
Zend_Mail::setDefaultTransport($tr);
$mail->setBodyText($body);


回答3:

Your example shows an empty link so it wont display anything.

Unless this is a modified example you used to post on here?

Does the following display anything when you run it, if not what do you get.

$smtpHost = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
                $mail = new Zend_Mail();
                $mail->setBodyText($form->getValue('body'));
                $mail->setBodyHtml('<a href = "http://localhost:8080/certificate/certificate-image/id/' . $id . '">my link</a>');
                $mail->setFrom($certtime['email'], $certtime['first_name'] . $certtime['last_name']);
                $mail->addTo($form->getValue('reciever'));
                $mail->setSubject('My Certificate');
                $mail->send($smtpHost);