如何使用相同的表单发送不同的电子邮件?
how to send different email with the same form?
我有一个用 fpdf 生成 pdf 的表单,我希望这个表单发送两封不同的电子邮件。一封给已经编制表格的客户(就像感谢按摩)和第二封给我的电子邮件,以便回答我的客户。
我有生成 pdf 并将电子邮件发送到无回复邮件的代码:
<?php
require('fpdf181/fpdf.php');
if(isset($_POST['submit'])){
$id_appartamenti = $_POST['id_appartamenti'];
$taglio = $_POST['taglio'];
$style = $_POST['style'];
$piano = $_POST['piano'];
$mq = $_POST['mq'];
$mood = $_POST['mood'];
$finiture = $_POST['finiture'];
$prezzo = $_POST['prezzo'];
$nome = $_POST['nome'];
$email = $_POST['email'];
//A4 width: 219 mm
//default margin: 10mm each side
//writable horizontal: 219 - (10*2)=189mm
$pdf = new FPDF('p', 'mm', 'A4');
$pdf->AddPage();
//set font to arial, bold, 14pt
$pdf->SetFont('Arial','B', 14);
//cell(width, height, text, border, endline, align)
//titolo
$pdf->Image('../images/favicon-outline-grigia.png',95, 2, 20, 20,0,1);
$pdf->Cell(0,30,'Buongiorno '.$nome.', ecco la configurazione del tuo '.$taglio.' '.$style.':',0,1,'C');
//img
$pdf->Cell(0,120,'',0,1);
$pdf->Image('../images/bilocale1.jpg',20, 40, 160, 120,0,1);
//corpo
//set font to arial, reg, 12pt
$pdf->SetFont('Arial','', 10);
//riga 1
$pdf->SetFillColor(230,230,230);
$pdf->Cell(130,8,'ID appartamento:',0,0,'L', true);
$pdf->Cell(59,8,''.$id_appartamenti.'',0,1,'L', true);//end of line
//riga 2
$pdf->SetFillColor(255,255,255);
$pdf->Cell(130,8,'Piano:',0,0,'L', true);
$pdf->Cell(59,8,''.$piano.'',0,1,'L', true);//end of line
//riga 3
$pdf->SetFillColor(230,230,230);
$pdf->Cell(130,8,'Mq:',0,0,'L', true);
$pdf->Cell(59,8,''.$mq.'',0,1,'L', true);//end of line
//riga 4
$pdf->SetFillColor(255,255,255);
$pdf->Cell(130,8,'Mood:',0,0,'L', true);
$pdf->Cell(59,8,''.$mood.'',0,1,'L', true);//end of line
//riga 5
$pdf->SetFillColor(230,230,230);
$pdf->Cell(130,8,'Finiture:',0,0,'L', true);
$pdf->Cell(59,8,''.$finiture.'',0,1,'L', true);//end of line
//riga 5
//set font to arial, bold, 14pt
$pdf->SetFont('Arial','B', 20);
$pdf->SetTextColor(234, 103 , 12);
$pdf->SetFillColor(255,255,255);
$pdf->Cell(130,50,'',0,0,'R', true);
$pdf->Cell(59,50,'Totale: '.$prezzo.' Euro',0,1,'R', true);//end of line
////////////////////////////////////////////////////////////prima mail al cliente
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// email stuff (change data below)
$to = "$email";
$from = "noreply@tecmasolutions.com";
$subject = "Tecma - la tua configurazione";
$message = "<p>Buongiorno $nome, in allegato potrai trovare le tua configurazione</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "$id_appartamenti.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
//NOTICE I changed $headers to $body!!
$body .= "Content-Transfer-Encoding: 7bit".$eol;
$body .= "This is a MIME encoded message.".$eol; //had one more .$eol
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol; //had one more .$eol
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
mail($to, $subject, $body, $headers);
////////////////////////////////////////////////////////////seconda mail al cliente
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// email stuff (change data below)
$to2 = "s.zanetti@tecmasolutions.com";
$from2 = "$email";
$subject2 = "Tecma - richiesta info per $id_appartamenti ";
$message2 = "<p>Una nuova richiesta da parte di $nome, per l'appartamento $id_appartamenti.</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "$id_appartamenti.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers2 = "From: ".$from.$eol;
$headers2 .= "MIME-Version: 1.0".$eol;
$headers2 .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
//NOTICE I changed $headers to $body!!
$body2 .= "Content-Transfer-Encoding: 7bit".$eol;
$body2 .= "This is a MIME encoded message.".$eol; //had one more .$eol
// message
$body2 .= "--".$separator.$eol;
$body2 .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body2 .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body2 .= $message.$eol; //had one more .$eol
// attachment
$body2 .= "--".$separator.$eol;
$body2 .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body2 .= "Content-Transfer-Encoding: base64".$eol;
$body2 .= "Content-Disposition: attachment".$eol.$eol;
$body2 .= $attachment.$eol;
$body2 .= "--".$separator."--";
/////////////////////////////////send message
/////////////////////////////////
/////////////////////////////////
/////////////////////////////////
mail($to2, $subject2, $body2, $headers2);
}
header('Location: ../thank-you.html');
?>
我怎样才能用另一个正文发送另一封邮件,但将相同的附件发送到另一封电子邮件(如 myemail@mydomani.com)?
尝试简单地添加第二个正文并执行邮件功能
<?php
require('fpdf181/fpdf.php');
if(isset($_POST['submit'])){
...
// send message NOTICE I replaced "" with $body
mail($to, $subject, $body, $headers);
$body2 = 'All you want to add to yourself';
mail('myemail@mydomani.com', 'Answer required', $body2, $headers);
}
header('Location: ../thank-you.html');
?>
您可以使用不同的 $to 参数再次调用邮件函数:
$to = "$email";
$to2 = "secondemailaddress@email.com";
// here a lot of your code
mail($to, $subject, $body, $headers);
mail($to2, $subject, $body, $headers);
您可以通过重复使用邮件功能来做到这一点:
mail($to, $subject, $body, $headers);
由于您的代码当前内容实际上是pdf形式,意味着它会发送给您,那么您只需要为客户创建感谢邮件即可。
这可以通过为感谢电子邮件创建新变量来完成:
$otherto = "someemail@email.com";
$subject2 = "Thank you subject.";
$body2 = "Thank you body";
mail ($to, $subject, $body, $from);
mail ($otherto, $subject2, $body2, $from);
我的建议是添加:
$headers .= 'Bcc: youremail@yourmail.com' . "\r\n";;
所以发送了一个隐藏的副本,地址不暴露给客户。
我有一个用 fpdf 生成 pdf 的表单,我希望这个表单发送两封不同的电子邮件。一封给已经编制表格的客户(就像感谢按摩)和第二封给我的电子邮件,以便回答我的客户。 我有生成 pdf 并将电子邮件发送到无回复邮件的代码:
<?php
require('fpdf181/fpdf.php');
if(isset($_POST['submit'])){
$id_appartamenti = $_POST['id_appartamenti'];
$taglio = $_POST['taglio'];
$style = $_POST['style'];
$piano = $_POST['piano'];
$mq = $_POST['mq'];
$mood = $_POST['mood'];
$finiture = $_POST['finiture'];
$prezzo = $_POST['prezzo'];
$nome = $_POST['nome'];
$email = $_POST['email'];
//A4 width: 219 mm
//default margin: 10mm each side
//writable horizontal: 219 - (10*2)=189mm
$pdf = new FPDF('p', 'mm', 'A4');
$pdf->AddPage();
//set font to arial, bold, 14pt
$pdf->SetFont('Arial','B', 14);
//cell(width, height, text, border, endline, align)
//titolo
$pdf->Image('../images/favicon-outline-grigia.png',95, 2, 20, 20,0,1);
$pdf->Cell(0,30,'Buongiorno '.$nome.', ecco la configurazione del tuo '.$taglio.' '.$style.':',0,1,'C');
//img
$pdf->Cell(0,120,'',0,1);
$pdf->Image('../images/bilocale1.jpg',20, 40, 160, 120,0,1);
//corpo
//set font to arial, reg, 12pt
$pdf->SetFont('Arial','', 10);
//riga 1
$pdf->SetFillColor(230,230,230);
$pdf->Cell(130,8,'ID appartamento:',0,0,'L', true);
$pdf->Cell(59,8,''.$id_appartamenti.'',0,1,'L', true);//end of line
//riga 2
$pdf->SetFillColor(255,255,255);
$pdf->Cell(130,8,'Piano:',0,0,'L', true);
$pdf->Cell(59,8,''.$piano.'',0,1,'L', true);//end of line
//riga 3
$pdf->SetFillColor(230,230,230);
$pdf->Cell(130,8,'Mq:',0,0,'L', true);
$pdf->Cell(59,8,''.$mq.'',0,1,'L', true);//end of line
//riga 4
$pdf->SetFillColor(255,255,255);
$pdf->Cell(130,8,'Mood:',0,0,'L', true);
$pdf->Cell(59,8,''.$mood.'',0,1,'L', true);//end of line
//riga 5
$pdf->SetFillColor(230,230,230);
$pdf->Cell(130,8,'Finiture:',0,0,'L', true);
$pdf->Cell(59,8,''.$finiture.'',0,1,'L', true);//end of line
//riga 5
//set font to arial, bold, 14pt
$pdf->SetFont('Arial','B', 20);
$pdf->SetTextColor(234, 103 , 12);
$pdf->SetFillColor(255,255,255);
$pdf->Cell(130,50,'',0,0,'R', true);
$pdf->Cell(59,50,'Totale: '.$prezzo.' Euro',0,1,'R', true);//end of line
////////////////////////////////////////////////////////////prima mail al cliente
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// email stuff (change data below)
$to = "$email";
$from = "noreply@tecmasolutions.com";
$subject = "Tecma - la tua configurazione";
$message = "<p>Buongiorno $nome, in allegato potrai trovare le tua configurazione</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "$id_appartamenti.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
//NOTICE I changed $headers to $body!!
$body .= "Content-Transfer-Encoding: 7bit".$eol;
$body .= "This is a MIME encoded message.".$eol; //had one more .$eol
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol; //had one more .$eol
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
mail($to, $subject, $body, $headers);
////////////////////////////////////////////////////////////seconda mail al cliente
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// email stuff (change data below)
$to2 = "s.zanetti@tecmasolutions.com";
$from2 = "$email";
$subject2 = "Tecma - richiesta info per $id_appartamenti ";
$message2 = "<p>Una nuova richiesta da parte di $nome, per l'appartamento $id_appartamenti.</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "$id_appartamenti.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers2 = "From: ".$from.$eol;
$headers2 .= "MIME-Version: 1.0".$eol;
$headers2 .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
//NOTICE I changed $headers to $body!!
$body2 .= "Content-Transfer-Encoding: 7bit".$eol;
$body2 .= "This is a MIME encoded message.".$eol; //had one more .$eol
// message
$body2 .= "--".$separator.$eol;
$body2 .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body2 .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body2 .= $message.$eol; //had one more .$eol
// attachment
$body2 .= "--".$separator.$eol;
$body2 .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body2 .= "Content-Transfer-Encoding: base64".$eol;
$body2 .= "Content-Disposition: attachment".$eol.$eol;
$body2 .= $attachment.$eol;
$body2 .= "--".$separator."--";
/////////////////////////////////send message
/////////////////////////////////
/////////////////////////////////
/////////////////////////////////
mail($to2, $subject2, $body2, $headers2);
}
header('Location: ../thank-you.html');
?>
我怎样才能用另一个正文发送另一封邮件,但将相同的附件发送到另一封电子邮件(如 myemail@mydomani.com)?
尝试简单地添加第二个正文并执行邮件功能
<?php
require('fpdf181/fpdf.php');
if(isset($_POST['submit'])){
...
// send message NOTICE I replaced "" with $body
mail($to, $subject, $body, $headers);
$body2 = 'All you want to add to yourself';
mail('myemail@mydomani.com', 'Answer required', $body2, $headers);
}
header('Location: ../thank-you.html');
?>
您可以使用不同的 $to 参数再次调用邮件函数:
$to = "$email";
$to2 = "secondemailaddress@email.com";
// here a lot of your code
mail($to, $subject, $body, $headers);
mail($to2, $subject, $body, $headers);
您可以通过重复使用邮件功能来做到这一点:
mail($to, $subject, $body, $headers);
由于您的代码当前内容实际上是pdf形式,意味着它会发送给您,那么您只需要为客户创建感谢邮件即可。
这可以通过为感谢电子邮件创建新变量来完成:
$otherto = "someemail@email.com";
$subject2 = "Thank you subject.";
$body2 = "Thank you body";
mail ($to, $subject, $body, $from);
mail ($otherto, $subject2, $body2, $from);
我的建议是添加:
$headers .= 'Bcc: youremail@yourmail.com' . "\r\n";;
所以发送了一个隐藏的副本,地址不暴露给客户。