[英]Send multiple attachment in mail phpmailer
如果代码第一次运行其他表单,则表单仍会提交并收到邮件,但特定表单提交邮件不会发送出错。 评论部分工作正常但我想要一个逻辑到所有形式
if (!!$filename) {
if(str_contains($filename, '#')){
$filename_arr = explode("#",$filename);
$target_path_arr = explode("#",$target_path);
foreach( $filename_arr as $k => $v ){
$mail->addAttachment($target_path_arr[$k], $v);
}
// $mail->addAttachment($_SERVER['DOCUMENT_ROOT'] . "/document/mobile-app-requirements-specifications-document-template.docx", "mobile-app-requirements-specifications-document-template.docx");
// $mail->addAttachment($_SERVER['DOCUMENT_ROOT'] . "/document/Agicent-General-Capabilities-Presentation-2022.pdf","Agicent-General-Capabilities-Presentation-2022.pdf");
// $mail->addAttachment($_SERVER['DOCUMENT_ROOT'] . "/document/5-Points-committment.png", "5-Points-committment.png");
}else{
$mail->addAttachment($target_path, $filename);
}
}
阅读并尝试理解下面的 function 也许它会对你有所帮助。
public function fnSendMailCareg($xlspath,$xlspath1,$xlspath2,$from,$to,$subject,$message,$cc1,$cc2,$cc3='',$cc4='')
{
include_once APPPATH . "third_party/PHPMailer/src/PHPMailer.php";
include_once APPPATH . "third_party/PHPMailer/src/SMTP.php";
include_once APPPATH . "third_party/PHPMailer/src/Exception.php";
if(isset($to)) {
$spilt = explode('@',$to);
$e = $spilt[0];
}
if(isset($from)) {
$spiltf = explode('@',$from);
if($spiltf[0] == 'support') $f = 'John_doe- '.$spiltf[0]; else $f = $spiltf[0];
}
// Instantiate a new PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer();
// Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->setFrom($from, $f); //i.e FROM email address
$mail->addAddress($to, $e);// i.e TO email address
if(isset($cc1)) {
$spilt1 = explode('@',$cc1);
$e1 = $spilt1[0];
if(isset($e1) && $e1 != ''){
$mail->AddCC($cc1, $e1);
}
}
if(isset($cc2)) {
$spilt2 = explode('@',$cc2);
$e2 = $spilt2[0];
if(isset($e2) && $e2 != ''){
$mail->AddCC($cc2, $e2);
}
}
if(isset($cc3)) {
$spilt3 = explode('@',$cc3);
$e3 = $spilt3[0];
if(isset($e3) && $e3 != ''){
$mail->AddCC($cc3, $e3);
}
}
if(isset($cc4)) {
$spilt4 = explode('@',$cc4);
$e4 = $spilt4[0];
if(isset($e4) && $e4 != ''){
$mail->AddCC($cc4, $e4);
}
}
if(isset($cc4) && $cc4 != ''){
$MyCustomBcc = $cc1.",".$cc2.",".$cc3.",".$cc4;
}else if(isset($cc3) && $cc3 != ''){
$MyCustomBcc = $cc1.",".$cc2.",".$cc3;
}else{
$MyCustomBcc = $cc1.",".$cc2;
}
$mail->Username = '**************';
$mail->Password = '****************';
$mail->Host = '*****************';
$mail->Subject = $subject;
$mail->Body = $message;
$mail->SMTPAuth = true;
// Enable TLS encryption over port 587
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->AddAttachment($xlspath);
$mail->AddAttachment($xlspath2);
$mail->AddAttachment($xlspath3);
$mail->isHTML(true);
$mail->CharSet = "UTF-8";
if($mail->send()) {
$response = 'Success';
}
else{
$response = 'Fail<br>'. $mail->ErrorInfo;
}
return $response;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.