I currently using PHPMailer to sending mail with attachment file in localhost and also in my server.
The problem I have is the attachment file does not receive in email when execute in server. But in other side, the attachment file receive perfectly when I execute on localhost.
Here is my simple code:
$email = new PHPMailer();
$email->From = 'william#msmedia.com.sg';
$email->FromName = 'John';
$email->Subject = 'Message Subject';
$email->Body = 'test';
$email->AddAddress( 'william#msmedia.com.sg' );
$file_to_attach = $_FILES["cv"]["tmp_name"];
$email->AddAttachment( $file_to_attach , $_FILES["cv"]["name"]);
return $email->Send();
Can anyone able to correct my mistake..?
Related
This question already has answers here:
Send attachments with PHP Mail()?
(16 answers)
Closed 5 years ago.
I need to send an email with an attachment with the standard php mail function. I can't use classes like phpmailer. PHP verison 5.3.
This is working so far.
mail($to,$subject,$content,$headers);
Can you help me out?
Use below code for send mail with attachment
$email = new PHPMailer();
$email->From = 'you#example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress#example.com' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
I came across an issue using PHPmailer that I just don't understand. I have an assist function redirect for the header function that works 100% in the position shown. It fails to work in the positions shown in the comments where I would like it to work. Everything else works perfectly regardless of where the redirect function is placed. Any ideas? This is also my first post so apologies in advance if there is already a solution which I couldn't find.
<?php
if(isset($_POST['replyall'])) {
redirect("index.php?leadreply"); // Why does this have to be here to work???? //
if(isset($_POST['chk1'])) {
$email = new PHPMailer();
$email->From = $_POST['author'];
$email->FromName = 'JGM Decorating';
$email->Subject = 'Reply to your contact request';
$email->Body = $_POST['comments'];
$email->AddAddress( $_POST['destination'] );
$file_to_attach = '../crm/gtcjgm.pdf';
$email->AddAttachment( $file_to_attach , 'Terms and Conditions.pdf' );
return $email->Send();
// I would like to have the redirect here but it doesn't work??//
} else {
$email = new PHPMailer();
$email->From = $_POST['author'];
$email->FromName = 'JGM Decorating';
$email->Subject = 'Reply to your contact request';
$email->Body = $_POST['comments'];
$email->AddAddress( $_POST['destination'] );
$file_to_attach = '';
$email->AddAttachment( $file_to_attach , 'Terms and Conditions.pdf' );
return $email->Send();
// I would like to have a different redirect here but it doesn't work??//
}
}
?>
This code:
return $email->Send();
Explanation: This will be returning the function and it will stop the process at this stage itself and after that whatever line you place it will not work. (E.g) Echo statement also will not work.
If you want to do both you have to do the mail sending process using Ajax and after that alone you have to redirect as per you need .
Since the return will stop the execution at that instant itself. So in order to do so you can use it with the hep of AJAX and then redirect it.
in my case, I have to add the email button on the file list but before it I must be signed first so that the file can be viewed, this email button when clicked the file will automatically be in the form of attachment when sending mail. In that cases is it possible without having to download the file first and then browse the file as attachment ?
Basic version (using php):
$email = new PHPMailer();
$email->From = 'you#example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress#example.com' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
Reference : Send attachments with PHP Mail()?
Using laravel 5.0:
Mail::send('emails.welcome', $data, function($message)
{
$message->from('us#example.com', 'Laravel');
$message->to('foo#example.com')->cc('bar#example.com');
$message->attach($pathToFile);
});
Refer : Laravel mail
I have a PHPMailer script. It's working fine on my Hostinger account, but when I move it over to my company's FatCow server it stops working.
Any help would be much appreciated!
The code is:
$email = new PHPMailer();
$email->IsSendmail();
$email->From = "stuart#ubrew.cc";
$email->FromName = "Stuart";
$email->Subject = "Subject...";
$email->Body = "text"; // BODY TEXT HERE
$email->AddAddress("$customeremail");
$email->AddAttachment($certificateName, 'GiftCertificate.pdf');
if (!$email->Send()) {
$message = $email->ErrorInfo;
mail('sewelly#gmail.com', 'MAILER ERROR', $message);
}
I'm trying to send an order confirmation and also notify the seller about a user purchase. However, PHPMailer only sends the first email. Here's quick and dirty:
$bodytext = 'Mail.';
$email = new PHPMailer();
$email->From = 'mail#mail.com';
$email->FromName = 'Sender';
$email->Subject = 'Subject';
$email->Body = $bodytext;
$email->AddAddress($_REQUEST['sahkoposti']);
$email->AddAttachment($path, 'kuitti'.$ordernumber.'.pdf');
return $email->Send();
?>
<?php
//send message to seller
$bodytext = 'Mail.';
$email = new PHPMailer();
$email->From = 'mail#mail.com';
$email->FromName = 'Sender';
$email->Subject = 'Tilaus vastaanotettu';
$email->Body = $bodytext;
$email->AddAddress("mail#mail.com");
$email->AddAttachment($path, 'kuitti'.$ordernumber.'.pdf');
return $email->Send();
?>
Is it even possible to send multiple emails from one script?
It is possible, however you're using return in the first statement, which will stop execution of the function. Remove the first return (just use $email->Send();) and it should work.
The second email does not get executed because you are returning right after sending the first email, you should change:
return $email->Send();
for this:
$email->Send();