我有一个在线休假申请表,我有一些字段,我可以创建,查看和修改该表格。我还想再做一件事。无论给出所有这些字段的值,例如休假类型,天数,原因等等。我只想获取所有这些值,我想通过邮件发送它。在创建表单中,我将为所有字段赋值。当我点击“创建”按钮时,它应该发送一封包含这些详细信息的电子邮件。
这是actionCreate的控制器代码。这里我怀疑这一行=> $ mailmsg =(数组(' id' => $ model-> leave_id));
public function actionCreate()
{
$model=new EmpLeave;
$model->dateof_leave = date("Y-m-d H:i");
if(isset($_POST['EmpLeave']))
{
$model->attributes=$_POST['EmpLeave'];
if($model->save())
$recipients = "sridhar.venkatesan53@gmail.com";
$headers["From"] = "noreply@elixir.in";
$headers["To"] = "sridhar.venkatesan53@gmail.com";
$headers["Subject"] = "User feedback";
$mailmsg = (array('id'=>$model->leave_id));
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "smtp.mandrillapp.com";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "noreply@elixir.in";
$smtpinfo["password"] = "oNkeBOEA5MfaN_24loUs1w";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
$this->redirect(array('view','id'=>$model->leave_id));
}
$this->render('create',array(
'model'=>$model,
));
}
这是我的view.php
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'leave_id',
'leave_type',
'leave_reason',
'numof_days',
'type',
'dateof_leave',
),
)); ?>
答案 0 :(得分:1)
你忘记了{}
if($model->save()){
.....
}
答案 1 :(得分:1)
您想将Inputed值作为Mail发送。您的邮件正文看起来像一个数组。它在发送之前作为字符串或html处理。
$mailmsg /*variable you are try to send as array .probably it must be string
$mailmsg=(array('id'=>$model->leave_id)) /*just try this for your own testing after you get idea about this*/
echo "<pre>";
print_r($mailmsg);
exit();
将帖子值从表单更改为消息文本的代码
$mailmsg="<div><ul>";
foreach($_POST as $key=>$value)
{
$mailmsg.="<li>".$key." - ".$value."</li>"; // String Generated
}
$mailmsg.="</ul></div>";
$ mailmsg包含html格式化字符串中表单输入的数据
public function actionCreate()
{
$model=new EmpLeave;
$model->dateof_leave = date("Y-m-d H:i");
if(isset($_POST['EmpLeave']))
{
$model->attributes=$_POST['EmpLeave'];
if($model->save())
{
require_once(Yii::app()->basePath.'/extensions/PearMail/Mail-1.2.0/Mail.php');
$recipients = "sridhar.venkatesan53@gmail.com";
$headers["From"] = "noreply@elixir.in";
$headers["To"] = "sridhar.venkatesan53@gmail.com";
$headers["Subject"] = "User feedback";
$mailmsg="<div><ul>";
foreach($_POST as $key=>$value)
{
$mailmsg.="<li>".$key." - ".$value."</li>";
}
$mailmsg.="</ul></div>";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "smtp.mandrillapp.com";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "noreply@elixir.in";
$smtpinfo["password"] = "oNkeBOEA5MfaN_24loUs1w";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
$this->redirect(array('view','id'=>$model->leave_id));
}
$this->render('create',array(
'model'=>$model,
));
}
答案 2 :(得分:1)
此代码足以发送。你只需要替换你的细节和身体信息
Yii::import('application.extensions.phpmailer.JPhpMailer');
$mail = new JPhpMailer;
$mail->IsSMTP();
$mail->Host = 'smpt.163.com'; // your host and smtp address
$mail->SMTPAuth = true;
$mail->Username = 'yourname@163.com'; //login username
$mail->Password = 'yourpassword'; //login password
$mail->SetFrom('yourname@163.com', 'yourname'); //from
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress('john.doe@otherdomain.com', 'John Doe');
$status=$mail->Send();
print_r($status);