php代码
$sendTo = $this->getRequest()->getPost('sendTo');
if($sendTo) {
$subject = $this->getRequest()->getPost('subject');
$content = $this->getRequest()->getPost('content');
$mail = new Zend_Mail("UTF-8");
$config = array('auth' => 'login', 'username' => $this->_email,
'password' => $this->_password, 'ssl' => $this->_ssl, 'port' => 465);
$mailTransport = new Zend_Mail_Transport_Smtp($googleSmtp, $config);
if($_FILES['attach']['tmp_name'] != '') {
$attach = $mail->createAttachment(file_get_contents($_FILES['attach']['tmp_name']));
$attach->type = $_FILES['attach']['type'];
$attach->filename = $_FILES['attach']['name'];
}
$mail->setBodyHtml($content);
$mail->setSubject($subject);
$mail->setFrom($this->_email, $this->_email);
$sendToArr = explode(';',$sendTo);
foreach ($sendToArr as $send){
$mail->addTo($send, $send);
try {
$rs = $mail->send($mailTransport);
} catch (Exception $e) {
$this->getSession()->addError('send mail failed ,please check the send to email and try again');
$this->_redirect("$this->_module/$this->_controller/send-mail");
}
}
$this->getSession()->addSuccess('send mail succeed at ' . $rs->getDate());
$this->_redirect("$this->_module/$this->_controller/index");
}
html代码:
<form action="<?php echo $baseUrl.'/'.$module.'/'.$controller;?>/send-mail/" method="post" enctype="multipart/form-data">
<table width="100%">
<tr><th colspan="2"><h2>Send Mail</h2></th></tr>
<tr><td width="20%">send to</td>
<td width="80%"><input type="text" name="sendTo" value="<?php echo $from;?>"/></td></tr>
<tr><td width="20%">subject</td>
<td width="80%"><input type="text" name="subject" value="<?php echo $subject;?>"/></td></tr>
<tr><td width="20%">content</td>
<td width="80%"><textarea name="content" cols="30" rows="7"></textarea></td></tr>
<tr><td>Add attach file</td><td><input type="file" name="attach"></input></td></tr>
</table>
<input type="submit" value="send"/>
</form>