我有一个使用zend框架一次发送多封电子邮件的表单,用冒号分隔它们。
有没有办法阻止发送数据库中已经存在的电子邮件并发送那些不存在的电子邮件?
这里有一些:
html -----
<form method="post" action="<?php echo $this->url(array(), 'inviteByEmail'); ?>">
<table><tr>
<td>Email Addresses:* <span class="right small_font" style="margin-right:25px;">* Each email address must be separated by a comma ( , )</span></td>
<td></td>
</tr><tr>
<td><input class="input_long" type="text" name="emails" /></td>
</tr><tr>
<td><br/>Personalize your message:</td>
</tr><tr>
<td><textarea cols="49" rows="7" name="personal_message" id="share-text" style="margin-bottom:8px;" placeholder="Download Ad-Aware and help me get PRO version" ></textarea></td>
</tr><tr>
<td rowspan="3" valign="top">
<input type="submit" class="btn_submit_step3" id="btn_friends" value="share_friends" /><br/>
</td>
</tr></table>
</form>
控制器动作-----
public function inviteByEmailAction()
{
$emails = $this->getRequest()->getParam('emails');
$personal_message = $this->getRequest()->getParam('personal_message');
$emails = explode(",", $emails);
foreach ($emails as $email)
{
$email = trim($email);
$validator = new Zend_Validate_EmailAddress();
if ($validator->isValid($email))
{
if ($this->_helper->model('EmailInvites')->noRowByFields(array('email' => $email, 'referred_by_user_id' => $this->_helper->user()->id)))
{
$email_invite = $this->_helper->model('EmailInvites')->createRow();
$email_invite->email = $email;
$email_invite->personal_message = $personal_message;
$email_invite->referred_by_user_id = $this->_helper->user()->id;
$email_invite->save();
$this->_helper->user()->sendInviteEmail($email, $personal_message);
}
}
}
$this->getHelper('redirector')->gotoRoute(array(), 'invite');
}
并且模型具有发送电子邮件的功能。