我有一个表单可以上传PDF以使用PHPMailer类发送电子邮件附件。
我的表单要求上传标题和pdf:
如果用户没有填写我的字段,他会收到一条消息说填写所有字段,否则会将我的文件上传到我的简报文件夹。
然后我使用我的函数sendEmail
向我的电子邮件发送我的附件,但它不适用于大尺寸的PDF。
我测试了259kb的宽度PDF并且工作正常,但是对于489kb(仅200kb以上)的PDF不起作用,我总是得到同样的错误:
class.smtp.php
超过了30秒的最长执行时间
我的PHP代码:
if(isset($_POST['send_form']))
{
$f['subject'] = $_POST['subject'];
if(in_array('',$f) || empty($_FILES['img']['tmp_name']) )
{
echo '<span>Please Fill all fields!</span>';
}
else
{
if(!empty($_FILES['img']['tmp_name']))
{
$folder = '../newsletter/';
$year = date('Y');
$month = date('m');
if(!file_exists($folder.$year)){
mkdir($folder.$year,0755);
}
if(!file_exists($folder.$year.'/'.$month)){
mkdir($folder.$year.'/'.$month,0755);
}
$pdf= $_FILES['pdf'];
$ext = substr($pdf['name'],-3);
$f['pdf'] = $f['subject'].".".$ext;
$attachment = $folder.$year.'/'.$month.'/'.$f['pdf'];
move_uploaded_file($pdf['tmp_name'], $folder.$year.'/'.$month.'/'.$f['pdf']);
}
}
}
然后我发送电子邮件:
sendMail($f['subject'],$msg,MAILUSER,'Name of sender','testEmail03@hotmail.com', 'emailReceptor03@hotmail.com');
我的功能sendEmail
:
function sendMail($subject,$message,$emissor,$emissorName,$receptor,$receptorName, $attachment, $reply = NULL, $replyName = NULL){
require_once('mail/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->SMTPSecure = "tls";
$mail->Host = MAILHOST;
$mail->Port = MAILPORT;
$mail->Username = MAILUSER;
$mail->Password = MAILPASS;
$mail->From = utf8_decode($emissor);
$mail->FromName = utf8_decode($emissorName);
$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($message);
$mail->AddAddress(utf8_decode($receptor),utf8_decode($receptorName));
$mail->AddAttachment($attachment);
if($reply != NULL){
$mail->AddReplyTo(utf8_decode($reply),utf8_decode($replyNome));
}
if($mail->Send()){
return true;
}
else{
return false;
}
}
如果我将我的php.ini max_execution_time = 30更改为max_execution_time = 60,我不会收到错误但我没有收到任何电子邮件!