Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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      = 'john@hotmail.com';
$email->FromName  = 'John';
$email->Subject   = 'Message Subject';
$email->Body      = 'test';
$email->AddAddress( 'william@hotmail.com' );

$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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...