PHPMailer
The classic email sending library for PHP
I'm building a fairly simple php script that will need to send some emails with attachments. I've found these 2 libraries to do this. Does either one have significant advantages over the other? Or should I just pick one at random and be done with it?
Source: (StackOverflow)
ok, i don't know how the data should be formatted for AddAddress PHPMailer function; i need the email to be sent to multiple recipients so i tried
$to = "me@domain.com,you@domain.net,she@domain.it";
$obj->AddAddress($to);
but with no success. any help will be appreciated. thanks
Source: (StackOverflow)
I´m having trouble sending a e-mail with the PHPMailer class, but it works with PEAR Mail::factory.
I guess the problem is with the SMTP authentication, but I couldn´t find the problem.
The code with problem is:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = 'mail.xxx.com.br'; // my host here
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = 'xxx@xxx.com.br'; // a valid email here
$mail->Password = '***'; // the password from email
$mail->From = 'from@xxx.com.br';
$mail->SMTPDebug = true;
$mail->AddReplyTo('from@xxx.com.br', 'Test');
$mail->FromName = 'Test SMTP';
$mail->AddAddress('teste@xxx.com.br', 'teste@xxx.com.br');
$mail->Subject = 'Test SMTP';
$mail->IsHTML(true);
$mail->Body = '<b>Teste</b><br><h1>teste 2</h1>';
//$mail->Send();
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
?>
The code with PEAR that works is:
<?php
include('Mail.php');
include('Mail/mime.php');
$text = 'Versao em texto';
$html = '<html><body>Versao de email em <b>HTML</b></body></html>';
$crlf = "\n";
$hdrs = array(
'From' => 'from@xxx.com.br',
'Subject' => 'Test - mail.php'
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail = Mail::factory('smtp',
array ('host' => 'mail.xxx.com.br',
'debug'=> true,
'auth' => true,
'username' => 'xxx@xxx.com.br',
'password' => '***'));
$mail->send('teste@xxx.com.br', $hdrs, $body);
?>
When I run the code with problem with debug activated (SMTPDebug = True) I got:
SMTP -> FROM SERVER:
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
"
SMTP -> get_lines(): $str is "220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
"
SMTP -> get_lines(): $str is "220 and/or bulk e-mail.
"
SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
"
SMTP -> FROM SERVER:
220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
SMTP -> ERROR: EHLO not accepted from server: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $str is "250-SIZE 20971520
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
"
SMTP -> get_lines(): $str is "250-PIPELINING
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
"
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
"
SMTP -> get_lines(): $str is "250-STARTTLS
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
SMTP -> get_lines(): $str is "250 HELP
"
SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
"
SMTP -> FROM SERVER:
250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> get_lines(): $data is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
"
SMTP -> ERROR: AUTH not accepted from server: 250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6]
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "503 AUTH command used when not advertised
"
SMTP -> get_lines(): $data is "503 AUTH command used when not advertised
"
SMTP -> FROM SERVER:
503 AUTH command used when not advertised
SMTP -> ERROR: RSET failed: 503 AUTH command used when not advertised
Message could not be sent. <p>Mailer Error: SMTP Error: Could not connect to SMTP host.
And the debug result of the PEAR Mail code is:
DEBUG: Recv: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Tue, 04 Aug 2009 19:37:10 -0300
DEBUG: Recv: 220-We do not authorize the use of this system to transport unsolicited,
DEBUG: Recv: 220 and/or bulk e-mail.
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG: Recv: 250-SIZE 20971520
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250-STARTTLS
DEBUG: Recv: 250 HELP
DEBUG: Send: STARTTLS
DEBUG: Recv: 220 TLS go ahead
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6]
DEBUG: Recv: 250-SIZE 20971520
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250 HELP
DEBUG: Send: AUTH LOGIN
DEBUG: Recv: 334 VXNlcm5hbWU6
DEBUG: Send: c2lzdGVtYWFkbWluQGJvbW10ZW1wby5jb20uYnI=
DEBUG: Recv: 334 UGFzc3dvcmQ6
DEBUG: Send: RVkyYVM4YnpMNU5k
DEBUG: Recv: 235 Authentication succeeded
DEBUG: Send: MAIL FROM:
DEBUG: Recv: 250 OK
DEBUG: Send: RCPT TO:
DEBUG: Recv: 250 Accepted
DEBUG: Send: DATA
DEBUG: Recv: 354 Enter message, ending with "." on a line by itself
DEBUG: Send: MIME-Version: 1.0
From: sistemaadmin@bommtempo.com.br
Subject: Teste de mail - mail.php
Content-Type: multipart/alternative;
boundary="=_b3c5407ccf494306d78fbb35800efe65"
--=_b3c5407ccf494306d78fbb35800efe65
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
Versao em texto
--=_b3c5407ccf494306d78fbb35800efe65
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="ISO-8859-1"
Versao de email em HTML--=_b3c5407ccf494306d78fbb35800efe65--
.
DEBUG: Recv: 250 OK id=1MYSd4-0005Ky-Jw
DEBUG: Send: QUIT
Source: (StackOverflow)
Possible Duplicate:
PHPMailer AddAddress()
Here is my code.
require('class.phpmailer.php');
$mail = new PHPMailer();
$email = 'email1@test.com, email2@test.com, email3@test.com';
$sendmail = "$email";
$mail->AddAddress($sendmail,"Subject");
$mail->Subject = "Subject";
$mail->Body = $content;
if(!$mail->Send()) { # sending mail failed
$msg="Unknown Error has Occured. Please try again Later.";
}
else {
$msg="Your Message has been sent. We'll keep in touch with you soon.";
}
}
The Problem
if $email value is only 1. It will send. But multiple don't send. What should I do for this. I know that in mail function you have to separate multiple emails by comma. But not working in phpmailer.
Source: (StackOverflow)
I would like to send an email using Gmail SMTP server through PHP Mailer.
this is my code
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'MyUsername@gmail.com';
$mail->Password = 'valid password';
$mail->SMTPAuth = true;
$mail->From = 'MyUsername@gmail.com';
$mail->FromName = 'Mohammad Masoudian';
$mail->AddAddress('anotherValidGmail@gmail.com');
$mail->AddReplyTo('phoenixd110@gmail.com', 'Information');
$mail->IsHTML(true);
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = "Hello";
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
?>
but i recieve this following error
Mailer Error: SMTP Error: The following recipients failed: anotherValidGmail@gmail.com
SMTP server error: SMTP AUTH is required for message submission on port 587
my domain is vatandesign.ir
Source: (StackOverflow)
I'm using phpmailer on my website and to help with spam issues I have created a mailbox to send these emails from (using SMTP).
I have set the emails to come from the mailbox address and then I have added a reply to address for where I want the replies to go to:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tsl';
$mail->SMTPDebug = 1;
$mail->Host = EMAIL_HOST;
$mail->Port = EMAIL_PORT;
$mail->Username = EMAIL_USER;
$mail->Password = EMAIL_PASS;
$mail->SetFrom('mailbox@email.com', 'Mailbox name');
$mail->AddReplyTo('replyto@email.com', 'Reply to name');
$mail->AddAddress('user@email.com', 'User name);
The emails send successfully and seem to get through the spam filters ok, but when I press reply it includes both the mailbox account and the reply to account.
Is this what is meant to happen? I only want the reply to address to appear when you press reply. Is this even possible?
Many thanks in advance for any help offered!
Edit:
Looking at the email headers it seems like the from address is getting included in the reply to field. I have no idea why!
Date: Tue, 1 May 2012 11:16:25 +0100
To: User name <user@email.com>
From: Mailbox name <mailbox@email.com>
Reply-to: Mailbox name <mailbox@email.com>, Reply to name <replyto@email.com
Subject: Email subject
Message-ID: <54c530c0d1f3ff33fc87c4c41c2c9ffd@localhost>
X-Priority: 3
X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_54c530c0d1f3ff33fc87c4c41c2c9ffd"
--b1_54c530c0d1f3ff33fc87c4c41c2c9ffd
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit
Source: (StackOverflow)
I'm trying to use PHPMailer for a small project, but I'm a bit confused about error handling with this software. Hoping someone has experience with it. When I've set up an email and I use:
$result = $mail->Send();
if(!$result) {
// There was an error
// Do some error handling things here
} else {
echo "Email successful";
}
Which works fine, more or less. The problem is when there's an error, PHPMailer also seems to echo the error out, so if there's a problem, it just sends that info directly to the browser, essentially breaking any error handling I"m trying to do.
Is there a way to silence these messages? Its not throwing an exception, its just printing out the error, which in my test case is:
invalid address: @invalid@email You must provide at least one recipient email address.
Its meant to be an error, but it should be residing in $mail->ErrorInfo; not being echo'd out by the software.
Source: (StackOverflow)
I've used PHPMailer on several projects but now I'm stuck. It gives me the error:
SMTP Error: Could not connect to SMTP host.
I've tried sending email from Thunderbird and it works ! But not through PHPMailer ... Here are the settings from Thunderbird:
Server name: mail.exampleserver.com
Port: 587
Username: user@exampleserver.com
Secure Authentication: No
Connection Security: STARTTLS
I've compared these with the server at my last project where I used PHPMailer and they were:
Server name: mail.exampleserver2.com
Port: 465
Username: user@exampleserver2.com
Secure Authentication: No
Connection Security: SSL/TLS
My php code is:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = SMTP_HOST; // SMTP servers
$mail->Port = SMTP_PORT; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password
$mail->From = MAIL_SYSTEM;
$mail->FromName = MAIL_SYSTEM_NAME;
$mail->AddAddress($aSecuredGetRequest['email']);
$mail->IsHTML(true); // send as HTML
Where I am wrong?
Source: (StackOverflow)
I have the same php script running on localhost - my PC with XAMPP and on a hosted server. It works from my PC, but not from the hosted server.
When I send it from the hosted server, I get the following output:
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> ERROR: RCPT not accepted from server: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message. dev.camppage.com 550-(patchvalues.com) [205.234.141.238]:50958 is not permitted to relay through 550 this server without authentication.
SMTP Error: The following recipients failed: jdorner4@gmail.com FAILED
I suspect there is a configuration setting that needs to be changed on the server, but I don't know which one. Any advice would be greatly appreciated!
Here is the code:
function send_gmail ($recipients, $subject, $message, $attachment_filenames = array())
{
global $email_address, $email_password, $email_name;
require_once ($_SERVER['DOCUMENT_ROOT']. '/php/PHPMailer/class.phpmailer.php');
$body = $message;
$body = str_replace("\\", '', $body);
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing) 0 - none; 1 - errors & messages; 2 - messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Port = 465; // set the SMTP port
$mail->Username = $email_address; // GMAIL username
$mail->Password = $email_password; // GMAIL password
$mail->SetFrom($email_address);
$mail->FromName = $email_name;
$mail->AddReplyTo($email_address,$email_name);
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
if (isset ($recipients[0]))
{
foreach ($recipients AS $to)
{
$to_pieces = explode (",", $to, 2);
$to_email = trim ($to_pieces[0]);
if (isset ($to_pieces[1]))
$to_name = trim ($to_pieces[1]);
else
$to_name = " ";
$mail->AddAddress($to_email, $to_name);
}
$mail->IsHTML(true); // send as HTML
if ($mail->Send()){
return TRUE;
} else {
return FALSE;
}
}
else
{
return FALSE;
}
}
TIA
Source: (StackOverflow)
I am facing problem in sending mail to my inbox (gmail account) but everytime it goes to spam folder.
Here is the code snippet
//$ticketDetail is array which contain required information to send.
sendOwnershipEmail('dineshnagarscriet@gmail.com', $ticketDetail);
function sendOwnershipEmail($email, $ticketDetail) {
$param = new stdClass();
$param->content = "<div>
<div><b>".$ticketDetail[0]['ticket_number']."</b></div><br/>
<div><img src='".$ticketDetail[0]['image_path']."'/></div><br/>
<div>Ticket with ticket number ".$ticketDetail[0]['ticket_number']." has been requested for tranfer from <div/>
<div>".$ticketDetail[0]['oldDepartment']." to ".$ticketDetail[0]['newDepartment']." Department <div/>
</div>";
$param->sendTo = $email;
$param->subject = "Request for Department transfer";
sendMailFunction($param);
}
function sendMailFunction($param) {
$to = $param->sendTo;
$subject = $param->subject;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: successive.testing@gmail.com' . "\r\n";
$message = "<html><head>" .
"<meta http-equiv='Content-Language' content='en-us'>" .
"<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" .
"</head><body>" .$param->content.
"<br><br></body></html>";
mail($to, $subject, $message, $headers);
}
And I have tried a lot like setting headers as Reply-To, Return-Path etc but every time it goes to spam.
Can u please figure out whats the problem?
Source: (StackOverflow)
I'm trying to figure out this issue for 6 hours. But there is nothing to make sense. Here is the scenario; There is a well formatted HTML
template.
$mail_body = '
<b>Message Num :</b> 769<br />
<b>Message Date :</b> 2013-04-08 09:03:21<br />
<b>Name :</b> John Doe<br />
<b>Phone :</b> 123456789<br />
<b>E-mail :</b> abcdf@somedomain.com<br />
<b>Message :</b> Here is the message info<br />
';
Here is the array of recipients' mails;
$recipients = array("abc@something.com","xyz@somtehing.com");
Everything looks fine and email ready to send.Here is the phpmailer config;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->From = "noreply@something.com";
$mail->FromName = "TEST";
$mail->WordWrap = 50;
foreach($recipients as $mail_add) {
$mail->AddAddress($mail_add);
}
$mail->IsHTML(true);
$mail->Subject = "TEST Subject";
$mail->Body = $mail_body;
if(!$mail->Send()) {
echo $mail->ErrorInfo;
} else {
echo "Mail sent...";
}
Everything is same when I test it. But sometimes email was sent. Sometimes it was not sent. Give me the following error : The following SMTP Error: Data not accepted.
I hope I explained
Source: (StackOverflow)
Im having problems with gmail smtp server. I already read many posts here in StackOverflow about that subject.
The best post i found about test the connection is this one.
Although it is very well explained the error im getting i couldnt find a answer:
Google SMTP just says "Please log in via your web browser and then try again". Im completely sure that the password and the email (both in base64) are well encoded.
As you can see here, in this image:
,
there is just one difference i can notice: the user@gmail.com and password is sent in two steps. In the link above the guy sends both at the same time. Google didnt accepted that.
But the fact is, i write
auth login Y29udGF0...
(user in base64, googles responds: )
334 UGFzc3dvcmQ6
(wich means "Password: ")
YzQ2MjJmNWVi.... (paste my password in base64 and hit "enter")
Then Goggle says:
Please log in via your web browser and then try again.
534-5.7.14 Learn more at https://support.google.com/mail/bin/answer.py?answer=787
And, by the way, that page is 404.
And im going throgh all this problem because @MediaTemple and @DreamHost are not working with PHPMailer. I already use PHPMailer for a long time ago, in so many different hosts, using SMTP but failed with (mt) and Dreamhost. Now im in middle of a project that it >must< work on these two hosts.
Any help is very appreciate.
Thank you.
Source: (StackOverflow)
There are a lot of StackOverflow questions on this topic, but I couldn't find one that was able to help with the issue I'm having. The script that I'm writing sends out multiple emails to various recipients with different message contents.
I can get this working by re-initializing the phpMailer
object multiple times, but what I'd like to be able to do is create the object a single time, and then re-assign the following fields:
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->IsHTML(false);
$mail->Body = $message;
That way I can just run those four lines of code and then send the mail out, again and again, as many times as necessary. The Subject
, IsHTML
, and Body
fields are easily changed, so the problem I'm having is in the AddAddress
function.
As you can probably guess, after I send out the first email, changing recipients for future emails will result in those stacking onto the current list of recipients.
To put it simply, how can I remove the email addresses associated with my $mail
object so that I can assign them each time while removing the old addresses?
Is there another function besides AddAddress
that I can use that will just assign the addresses?
Source: (StackOverflow)
I have a form on example.com/contact-us.php
that looks like this (simplified):
<form method="post" action="process.php" enctype="multipart/form-data">
<input type="file" name="uploaded_file" id="uploaded_file" />
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
</form>
In my process.php
file, I have the following code utilizing PHPMailer()
to send an email:
require("phpmailer.php");
$mail = new PHPMailer();
$mail->From = me@example.com;
$mail->FromName = My name;
$mail->AddAddress(me@example.com,"John Doe");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Contact Form Submitted";
$mail->Body = "This is the body of the message.";
The email sends the body correctly, but without the Attachment of uploaded_file
.
MY QUESTION
I need the file uploaded_file
from the form to be attached to the email, and sent. I do NOT care about saving the file after the process.php
script sends it in an email.
I understand that I need to add AddAttachment();
somewhere (I'm assuming under the Body
line) for the attachment to be sent. But...
- What do I put at the top of the
process.php
file to pull in the file uploaded_file
? Like something using $_FILES['uploaded_file']
to pull in the file from the contact-us.php page?
- What goes inside of
AddAttachment();
for the file to be attached and sent along with the email and where does this code need to go?
Please help and provide code!Thanks!
Source: (StackOverflow)
I try to use PHPMailer to send registration, activation. etc mail to users:
require("class.phpmailer.php");
$mail -> charSet = "UTF-8";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.mydomain.org";
$mail->From = "name@mydomain.org";
$mail->SMTPAuth = true;
$mail->Username ="username";
$mail->Password="passw";
//$mail->FromName = $header;
$mail->FromName = mb_convert_encoding($header, "UTF-8", "auto");
$mail->AddAddress($emladd);
$mail->AddAddress("mytest@gmail.com");
$mail->AddBCC('mytest2@mydomain.org', 'firstadd');
$mail->Subject = $sub;
$mail->Body = $message;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
The $message is contain latin characters. Unfortunatelly all webmail (gmail, webmail.mydomain.org, emailaddress.domain.xx) use different coding.
How can i force to use UTF-8 coding to show my mail exactly same on all mailbox?
I try to convert the mail header width mb_convert_encoding(), but with no luck.
Thank you.
Source: (StackOverflow)