I have been trying to send emails with an attachment using PHPMailer. This worked fine. Then I decided to embed an image using the addEmbeddedImage-method.
Now I have a problem! The emails are received fine in gmail. But when I open the email in windows (using MS-Outlook) the attachment disappears!!
$mail = new PHPMailer;
//Server settings
$mail->SMTPDebug = 0; // Disable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailHost; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $mailUserName; // SMTP username
$mail->Password = $mailPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($mailSentFrom , $organisation);
$mail->addAddress($emailAdress, $recipientFullName);
//Attachments
$mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'].PHP_PATH.'/library-overrides/FPDF/images/small-logo.jpg', 'logo');
$mail->addStringAttachment($attachment, "$categoryName $seasonName, $recipientFullName.pdf", 'base64', 'application/pdf');
$mail->isHTML( true );
$mail->Subject = "$categoryName $seasonName";
$mail->Body = ""; // contains html version of email (omitted for readability)
$mail->AltBody = "";
$mail->send();
Any ideas how to fix this?
Related
I try to sent mail on submitting the form using the SMTP server. I get mail on my Gmail account but didn't get mail on webmail.
Is it an SMTP server issue or webmail?
What can I do to send mail on webmail?
Have to something remaining config in webmail?
Below I tried code:
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '**********'; // SMTP username
$mail->Password = '**********'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('info#abc.com','ABC');
$mail->addAddress($email); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'ABC - Register Successfully';
$mail->Body = "
<h4>Dear $name,</h4>
<p>Thank you! Your registration has been successful.</p>
<p>If you need any help or query, please feel free to drop an email using the following email address: <strong>info#abc.com</strong></p>
<p>We appreciate your patience. </p>
<h4>Thanking You,</h4>
";
$mail->send();
I use php to send email. It works perfectly, but I don't like that it outprints everything on the screen. I want this commant to remain silent. What should I do?
The command is the following:
verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '************#gmail.com'; // SMTP username
$mail->Password = '*********'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
//Recipients
$mail->setFrom('*********', 'Mailer');
$mail->addAddress('**************.com');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Want to get not';
$mail->Body = $_SESSION['nyelv'];
$mail->AltBody = $_POST['email1'];
$proba = $mail->send();
I need help please
this is my code:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = 'some#gmail.com';
$mail->Password = 'somepass';
$mail->addAddress('another#gmail.com', 'Josh Adams');
$mail->Subject = 'PHPMailer GMail SMTP test';
$body = 'This is the HTML message body in bold!';
$mail->MsgHTML($body);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
and I get this error:
2013-12-11 15:15:02 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. Mailer Error: SMTP connect() failed.
any help please?
You might want to start by isolating this problem to determine whether it's truly a network problem; or whether it's specific to PHP mailer or your code. On your server, from a command prompt, try using telnet to connect to smtp.gmail.com on port 587, like so:
telnet smtp.gmail.com 587
You should see a response from smtp.gmail.com, like so:
Trying 173.194.74.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP f19sm71757226qaq.12 - gsmtp
Do you see this, or does the connection attempt hang and eventually time out? If the connection fails, it could mean that your hosting company is blocking outgoing SMTP connections on port 587.
This worked for me:
change:
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
to
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '587';
The code below:
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Host = 'ssl://smtp.gmail.com:465';
I was facing the same issues on Godaddy hosting so I spend lots of time and fix it by disabling the SMTP restriction on the server end.
SMTP code is for PHPMailer
$mail = new PHPMailer(true);
try {
//Server settings
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->SMTPDebug = 2; //Enable verbose debug output
//$mail->isSMTP(); //Send using SMTP
$mail->Host = "tls://smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = contact#example.in;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Recipients
$mail->setFrom('contact#example.in', 'Online Order');
$mail->addAddress('test#gmail.com'); //Add a recipient
$mail->addReplyTo('contact#example.in', 'Jewellery');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Order';
$mail->Body = 'This is test email content';
$mail->AltBody = 'This is test email content';
if($mail->send()){
return '1';
}else{
return 'Order email sending failed';
}
change
$mail->SMTPSecure = "tls";
with
$mail->SMTPSecure = 'ssl';
I use class.phpmailer.php to send a confirmation email. It works perfectly in my local server, but when I upload it to the server in 000webhost.com it no longer works.
I just discovered mail() is not working anymore either.
Is there something I can do to solve this?
Here is the code of the function I use to send every mail in my system:
code
function correoEnviar($asunto, $mensaje, $mensajeTexto, $email)
{
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxx#yahoo.com.mx'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'xxxx#yahoo.com.mx';
$mail->FromName = 'xxxx';
$mail->addAddress($email); // Name is optional
$mail->addReplyTo('xxxx#yahoo.com.mx', 'Information');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
//$mail->Subject = 'Por favor confirme su correo para obtener el libro El fractal y el =?UTF-8?Q?dise=C3=B1o=C2=A0gr=C3=A1fico?=';
$mail->Subject = $asunto;
$mail->Body = $mensaje;
$mail->AltBody = $mensajeTexto;
if(!$mail->send()) {
return $mail->ErrorInfo;
}
else
return 1;
}
echo correoEnviar($asunto, $mensaje, $mensajeTexto, "recipent#gmail.com");
?>
code
Are you sure you are including the file class.phpmailer.php, your code seems fine.
Paste the server's mailserver log, it will provide a better insight.
Your code is fine, it might be a server issue.
A sample code showing SMTP settings
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn of SMTP authentication
$mail->Username = "YAHOO ACCOUNT"; // SMTP username
$mail->Password = "YAHOO ACCOUNT PASSWORD"; // SMTP password
$mail->SMTPSecure = "ssl";
$mail->Host = "YAHOO HOST"; // SMTP host
$mail->Port = 465;
I am sending emails using PHPMailer and through my gmail account with SMTP. It all works except when there is an & in the subject, then in my inbox the subject has &
Any way to make this not happen? I've tried setting the charset and encoding the subject.
My code is below
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "myusername#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('from#somesite.com', 'From Person');
$mail->AddReplyTo("from#somesite.com", "From Person");
$mail->Subject = 'An example with a & in the middle';
$mail->MsgHTML('Some text to send');
$mail->AddAddress('myusername#gmail.com');
$mail->Send()
Thank You
Try using this code, let me know if it helps.
$mail->Subject = "=?UTF-8?B?".base64_encode($_POST['subject'])."?=";