我正在尝试将目录中的pdf附加到电子邮件中。
这是我的php代码为pdf的候选邮件地址:
<?php
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$email = strip_tags($_POST['email']);
$name = strip_tags($_POST['name']);
$phone = strip_tags($_POST['phone']);
$candidateStatus = strip_tags($_POST['candidateStatus']);
$reference = strip_tags($_POST['reference']);
$result = array();
$file = "./doc/workshopPosterDesign1.pdf";
//For Admin
$adminSubject = "Registration for iOS Workshop - March'20,2019";
$fromAdmin = 'xxxx@smdev.co.in';
$toAdmin = 'yyyyy10@gmail.com';
$adminEmail = 'adminEmail.html'; // will find it on email-templates/ directory
$headersAdmin = "MIME-Version: 1.0\r\n";
$headersAdmin .= "Content-Type: text/html; charset=UTF-8\r\n";
$headersAdmin .= "From: " . $name . ' <' . $fromAdmin . '>' . "\r\n";
$headersAdmin .= "Reply-To: ". $email . "\r\n";
$returnpathAdmin = "-f" . $email;
//For Candidate
$candidateSubject = "Confirmation";
$toCandidate = $email; //put your email here
$candidateEmail = 'candidateEmail.html'; // will find it on email-templates/ directory
$headersCandidate = "MIME-Version: 1.0\r\n";
$headersCandidate .= "Content-Type: text/html; charset=UTF-8\r\n";
$headersCandidate .= "From: " . "CZ Smart Mobility Lab" . ' <' . $fromAdmin . '>' . "\r\n";
$headersCandidate .= "Reply-To: ". $fromAdmin . "\r\n";
$returnpathCandidate = "-f" . $fromAdmin;
$templateTags = array(
'{{subject}}' => $subject,
'{{name}}' =>$name
);
//preparing attachment
if(!empty($file) > 0){
if(is_file($file)){
$messageToCandidate .= "--{$mime_boundary}\n";
$fp = @fopen($file,"rb");
$data = @fread($fp,filesize($file));
@fclose($fp);
$data = chunk_split(base64_encode($data));
$messageToCandidate .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
"Content-Description: ".basename($file)."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$candidateEmail);
$contentsToCandidate = strtr($templateContents, $templateTags);
$templateTags = array(
'{{subject}}' => $subject,
'{{name}}' => $name,
'{{email}}' => $email,
'{{reference}}' => $reference,
'{{phone}}' => $phone,
'{{candidateStatus}}' => $candidateStatus,
);
$templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$adminEmail);
$contentsToAdmin = strtr($templateContents, $templateTags);
if ( mail( $toCandidate, $candidateSubject, $contentsToCandidate, $headersCandidate ,$returnpathCandidate) && mail( $toAdmin, $adminSubject, $contentsToAdmin, $headersAdmin ,$returnpathAdmin) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>Success!</strong> Mail Sent.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Cann\'t Send Mail.' );
}
echo json_encode( $result );
die;
这是我的候选html邮件模板:
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{{subject}}</title>
</head>
<body class="">
<table border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td> </td>
<td class="container">
<div class="content">
<!-- START CENTERED WHITE CONTAINER -->
<span class="preheader">One Day Workshop on Mobile App Design, Development and Digital Marketing</span>
<table class="main">
<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>
Hi {{name}},
<br><br>
Thankyou for registering the workshop for iOS App Development.<br>
<br>
Workshop Details:
<br><br>
Date: 20<sup>th</sup> March,2019.
<br><br>
Time: 9.30 AM to 3.45 PM
<br><br>
Venue: <br>
<pre>
1st Floor,TBI Office, <br>
jenni street 2ndk, <br>
pincode - 1000119.
</pre> <br>
</p>
</td>
</tr>
</table>
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- START FOOTER -->
<div class="footer">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block">
By: Mobility Lab.
</td>
</tr>
</table>
</div>
<!-- END FOOTER -->
<!-- END CENTERED WHITE CONTAINER --></div>
</td>
<td> </td>
</tr>
</table>
</body>
我有三个文件候选人邮件.html,adminmail.html和sendmail.php。当单击“提交”按钮时,我正在向求职者和管理员发送确认邮件。 现在,对于候选人,我希望保留完整的pdf以及详细信息。
我的问题我无法附加pdf html邮件模板。这是我的新手。