나는 PHPmailer 라이브러리를 사용하여 전자 메일을 보내고 첨부 파일을 보내야합니다.PHPmailer를 사용하여 첨부 파일 보내기
현재 파일이 서버에 저장되어 있으며 파일에 대한 링크가 var $link
에 저장되어 있습니다.
$phpmailer->AddAttachment('$link');
내가 대신 내 변수의 하드 코딩 된 경로를 시도했다 :
$phpmailer->AddAttachment('http://mysite.co.uk/link/to/my/file.pdf');
나는 시도하고 첨부 파일을 추가하려면 다음하지만 이메일이없는 첨부 파일이 도착 사용하고 있습니다
이메일에 나타나지만 첨부 파일이 없습니다.
나는 어떤 오류라도 잡기 위해 phpmailerException
을 사용해 보았지만 응답을 얻지 못했습니다.
그 외 어떻게 PHPmailer로 첨부 파일을 보낼 수 있습니까?
전체 PHP 코드 :
require_once 'library/PHPMailer.php';
$phpmailer = new PHPMailer();
$phpmailer->isSMTP(); //switch to smtp
$phpmailer->Host = 'smtp.sendgrid.net';
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->Port = 465;
$phpmailer->Username = 'username';
$phpmailer->Password = 'password';
$phpmailer->AddAttachment('http://mysite.co.uk/blah/cv.pdf');
//$phpmailer->AddAttachment('$link');
$subject = 'Job Application';
$messageConfirmation = "The <b> 'Apply for Job' </b> form has recently been completed on <b>www.mysite.com.</b><br/><br/> <b>Please see contact details below:<br /><br/> </b>";
$messageConfirmation.= "<b>Applying for:</b> $title <br/><br/>";
$messageConfirmation .= "<b>Name:</b> $name <br/><br/><b>Surname:</b> $surname <br/><br/> <b>Email:</b> $email <br/><br/> <b>Comment:</b> $comment <br/><br/>";
$messageConfirmation .= "<b>CV:</b> $link<br /><br />";
$messageConfirmation .= "Please can you call them back in the next 24 hours. <br/><br/> Thank you \n\nMy Site<br/><br/>";
$imgheader = 'http://blah.co.uk/blah/wp-content/uploads/2014/11/header.png';
$imgfooter = 'http://blah.co.uk/blah/wp-content/uploads/2014/11/footer.png';
$message = '<!DOCTYPE HTML>'.
'<head>'.
'<meta http-equiv="content-type" content="text/html">'.
'<title>Email notification</title>'.
'</head>'.
'<body>'.
'<div id="header" style="width: 600px;height: auto;margin: 0 auto;color: #fff;text-align: center;font-family: Open Sans,Arial,sans-serif;">'.
'<img src="'.$imgheader.'" >'.
'</div>'.
'<div id="outer" style="width: 600px;margin: 0 auto;margin-top: 10px;">'.
'<div id="inner" style="width: 600px;margin: 0 auto; padding-left: 20px;background-color: #fff;font-family: Open Sans,Arial,sans-serif;font-size: 13px;font-weight: normal;color: #444;margin-top: 10px;">'.
'<p>'.$messageConfirmation .'</p>'.
'</div>'.
'</div>'.
'<div id="footer" style="width: 600px;height: auto;margin: 0 auto;text-align: center;padding: 10px;font-family: Verdena;">'.
'<img src="'.$imgfooter.'" >'.
'</div>'.
'</body>';
$phpmailer->IsHTML(true);
$phpmailer->AddAddress(CONTACTUSFORMEMAIL);
$phpmailer->From = CONTACTUSFORMEMAIL;
$phpmailer->FromName ='blah';
$phpmailer->WordWrap = 50; // set word wrap to 50 characters
$phpmailer->Subject = $subject;
$phpmailer->Body = $message;
$phpmailer->Send();
$data['success'] = true;
$data['message'] = 'Thank you for your application';
서버가 아닌 다른 곳에 파일을 첨부 하시겠습니까? –
/home/x/public_html/pdf/d.pdf와 같은 파일 경로 추가 –