sending emails with empty body - php

Is there any reason why phpmailer will send emails with empty body on a remote server but works fine on a local server?
The code is the same
$res = $db->run("SELECT * FROM email WHERE code = 'welcome'");
$m = $res[0];
$body = nl2br($m['content']);
$body = str_replace("[EMAIL]", $ld['email'], $body);
$body = str_replace("[PASSWORD]", $ld['password'], $body);
$mail = new PHPMailer();
$mail->AddReplyTo($m['from_address'], $m['from_name']);
$mail->AddAddress($ld['email'], "");
$mail->SetFrom($m['from_address'], $m['from_name']);
$mail->Subject = $m['subject'];
$mail->AltBody = strip_tags($body);
$mail->MsgHTML($body);
if ($mail->Send() === false)
{
p($mail->ErrorInfo);
}
unset($mail);

If anybody finds this and has no clue just like me, an update to phpmailer 5.2.6 will fix this.

Related

PHPMailer send multiple emails fails

I'm having a problem with PHPMailer. I'm creating a page for job applications for a company. There is a form, which the applicant fills, and the form data is sent to the HR. Then there must be an automatic response from the server to the applicant which thanks the application. The first email to the HR is sent, but the second is not. The code is:
$mailer = new PHPMailer();
$mailer->From = "admin#bav.hu";
$mailer->FromName = "Báv gyakornoki jelentkezés";
$mailer->AddAddress("dudas.krisztian#nerddevelopments.com", "the subject");
$mailer->isHTML(true);
$mailer->CharSet = 'UTF-8';
$mailer->Subject = "Báv gyakornoki regisztráció";
$body = "The body with the form data to HR";
$mailer->Body = $body;
$mailer->AddAttachment($cv_path, $_FILES['cv']['name']);
$mailer->AddAttachment($motivation_letter_path, $_FILES['motivation']['name']);
$success = $mailer->send();
//this email gets sent
$autoresponse = new PHPMailer();
$autoresponse->From = "gyakornok#bav.hu";
$autoresponse->CharSet = "UTF-8";
$autoresponse->AddAddress($email);
$autoresponse->Subject = "This is an automatic message, please don't answer it";
$body = "This is the automatic response to the applicant";
$autoresponse->body = $body;
$autoresponse_sent = $autoresponse->send();
//this email won't get sent
Change
$autoresponse->body = $body;
to
$autoresponse->Body = $body;

How to change the name text of sender when sending mail with Swift Mailer v3.3.2

I'm using Swift Mailer v3.3.2 to send emails from my app and I need to be able to change the text of the sender.
My code looks like this:
//Sending email
$swift = email::connect();
$email_message = new View('email/email_template');
$subject = "Subject here";
$from = "subdomain#domain.org";
$email_message->content_email = new View('email/content/signup');
$email_message->content_email->user = $user;
$message = $email_message;
$recipients = new Swift_RecipientList;
$recipients->addTo($user->email);
// Build the HTML message
$message = new Swift_Message($subject, $message, "text/html");
if ($swift->send($message, $recipients, $from)) {
;
} else {
;
}
$swift->disconnect();
I want to be able to set the name text of the sender as 'Senders_Name Senders_Surname', even though the sender is still subdomain#domain.org
Any clue on how to do that?
After line
$message = new Swift_Message($subject, $message, "text/html");
you should add
$message->setFrom(new Swift_Address($from , 'Senders_Name Senders_Surname'));
The whole working script below (I've just tested it in 3.3.2 version):
<?php
require ('lib/Swift.php');
require('lib/Swift/Connection/SMTP.php') ;
$smtp = new Swift_Connection_SMTP();
$smtp->setServer('server');
$smtp->setUsername('username');
$smtp->setPassword('password');
$smtp->setEncryption($smtp::ENC_SSL);
$smtp->setPort(465);
$swift = new Swift($smtp);
$swift->connect();
$subject = "Subject here";
$from = 'test#email.com';
$message = 'test message';
$recipients = new Swift_RecipientList;
$recipients->addTo('mymail');
// Build the HTML message
$message = new Swift_Message($subject, $message, "text/html");
$message->setFrom(new Swift_Address($from , 'Senders_Name Senders_Surname'));
if ($swift->send($message, $recipients, $from)) {
;
} else {
;
}
$swift->disconnect();
Below image how the sender is displayed in email client (Thunderbird for me) so it works fine. If you test it in your email client make sure you don't have account from set as one of your mail accounts. In that case email client shows for example "Me" or sth else. The best for test just fill in addTo with your email and smtp settings and leave from and other parts unchanged

Pear Can't send email on Shared Hosting

I was working on a project for a client, it selects an email from a database and then sends an email to that address. Everything worked fine on my VPS server running CentOS 6, but when migrating to their shared hosting the program will no longer send the email. It will select the correct addresses, but no message will be sent, I've already installed Pear Mail and Mail_mime. Any thoughts?
This code connects to the server:
$headers['From'] = 'mail#openmailbox.org';
$headers['To'] = 'mail#openmailbox.org';
$headers['Subject'] = $asunto;
$params['host'] = 'smtp.openmailbox.org';
$params['port'] = '25';
$params['auth'] = 'PLAIN';
$params['username'] = 'mail#openmailbox.org';
$params['password'] = 'password';
This code selects the recipients:
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$addresses[] = $row['email'];
}
$recipients = implode(", ", $addresses);
Hope you can help me!
Here, this is my email sending code
$mail =& Mail::factory('smtp', $params);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail->send($recipients, $headers, $body);
Well, I solved it. I replaced pear mail with the default mail function.

Mail send with PHPMailer doesn't work

So I'm trying to use PHPMailer to handle the email form on my website.
I wrote the code here based on a tutorial I found.
<?php
error_reporting(E_ALL);
require_once("class.phpmailer.php");
include("class.smtp.php");
$email = new PHPMailer();
//
// Set server details for send
//
$email->IsSMTP();
$email->Host = "mail.loganyoung.za.net";
$email->Port = 25;
$email-SMTPAuth = true;
$email->Username = "<my email>";
$email->Password = "<my password>";
//
// Send mail from the contact form
//
$to = "<my email>";
$from = $_POST["from"];
$name = $_POST["name"];
$subject = "From web: ".$_POST["subject"];
$message = $_POST["message"];
$body = "<p>Hi Logan,</p>";
$body .= "<p>You have received a new query on your website.<br />Please see below:</p>";
$body .= "<p>";
$body .= str_replace("\r\n", "<br />", $message);
$body .= "</p>";
$email->SetFrom($from, $name);
$email->AddReplyTo($from, $name);
$email->AddAddress($to, "LoganYoung.za.net");
$email->Subject = $subject;
$email->Body = $body;
$email->IsHTML = true;
session_start();
if(!$email->Send()) {
$_SESSION["mailresult"] = "success";
echo "success";
} else {
echo "<p>Failed:</p><p>".$email->ErrorInfo."</p>";
$_SESSION["mailresult"] = "failed";
$_SESSION["mailerror"] = $email->ErrorInfo;
}
?>
I figure possible reasons for it not sending could be...
Incorrect SMTP details (possibly send without SMTP auth to resolve?)
Handler isn't getting POST data (the ajax that sends it seems to work fine though)
Some problem with this code that I'm not able to identify...
As a means of eliminating possibilities, can anyone spot anything wrong with the code here? If so, what's wrong, and how do I fix it?
Thanks in advance!
$email-SMTPAuth = true;
Isn't that supposed to be:
$email->SMTPAuth = true;

phpMailer Attachment not working

this is my first post and I hope that I can get some help regarding adding an attachment field in my phpMailer contact form. I have already added an uploader [browse] bar in the html website but I don't know how to link it with the phpmailer. do I have to declare it at the package which is phpmailer.php or do something with it?
I would really appreciate some help. Below is my desperate attempt.
Snippet from the code:
<?
$body = ob_get_contents();
$to = 'xxx#xxxx.com>';
$email = $email;
$subject = $subject;
$fromaddress = "xxx#xxxx.com";
$fromname = "Online Contact";
require("phpmailer.php"); //<<this is the original pack
$mail = new PHPMailer();
$mail->From = "xxx#xxxx.com";
$mail->FromName = "My Name";
$mail->AddBCC("xxx#xxxx.com","Name 1");
$mail->AddAddress( $email,"Name 2");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = "This is the text-only body";
// attachment
$mail->AddAttachment('uploadbar', 'new_file.pdf'); // the name of my html uploader is uploadbar, clicking browse to locate a file
if(!$mail->Send()) {
$recipient = 'xxx#xxxx.com';
$subject = 'Contact form failed';
$content = $body;
mail($recipient, $subject, $content, "From: xxx#xxxx.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
exit;
}
?>
Had the same problem, try this
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/file-name.pdf');
First, make sure your upload form has enctype='multipart/form-data' as in <form method=post action=file.php enctype='multipart/form-data'>.
then, use this code in your phpmailer handler file
foreach(array_keys($_FILES['files']['name']) as $key) {
$source = $_FILES['files']['tmp_name'][$key];
$filename = $_FILES['files']['name'][$key];
$mail->AddAttachment($source, $filename);
}
Make sure attachment file name should not contain any special character and check the file path also correct.
eg: [file name.pdf] Should be like [filename.pdf]

Categories