Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

php - Send attachment file using PHPMailer

Here my code that using PHPMailer to send attachment via mail using PHPMailer. I try this out in localhost it function perfectly. But once I upload to my server, the attachment is not sent.

$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'John';
$email->Subject   = 'Message Subject';
$email->Body      = 'test';
$email->AddAddress( '[email protected]' );

$file_to_attach = $_FILES["cv"]["tmp_name"];

$email->AddAttachment( $file_to_attach , $_FILES["cv"]["name"]);

return $email->Send();

I cant receive my attachment file and I upload.

Did I miss out any code..?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's nothing wrong with your code - it works fine for you on localhost (and also for me), so it must be an issue with your server environment. This could be several things:

Windows server with no mail server installed? It could be permissions for your uploaded files, or indeed the ability to upload files at all, since that is also controlled via php.ini.

I suggest you separate out the stages:

  • Upload a file and save it, check that it's there on the server.

  • Check that your PHP script can see and read the uploaded file (and please read the docs on how to do this correctly).

  • Send a simple email without attachments. If that works you know your mail server is ok.

When all the individual pieces are working, join them together.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...