phpmailer not handling Iphone subject line in emails - iphone

I am using the following script to email our website users:
function mailerExpressBlueHost(array $mailInputs){
require_once '../../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetFrom('swag#sustainablewestonma.org');
$mail->addAddress($mailInputs['addAddress']); // use for production;
$mail->AddBCC("swag#sustainablewestonma.org"); // set BCC: counts as part of the 500 limit;
$mail->AddEmbeddedImage("../images/newswagimageSmall.jpg", "swag-logo");
$mail->Subject = $mailInputs['subject'] ;
$mail->Body = $mailInputs['body'];
$mail->IsHTML(true);
$mail->ContentType="text/HTML";
if(!$mail->send()) {
$msg = 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
}else{
$msg = 'Message has been sent';
}
$mail->ClearAddresses();
return $msg;
}
when viewing the email in ms outlook the email looks like:
but when viewed on an Iphone it looks like:
Is there a way to either hide or place in the header the subject line instead of it appearing in the body? (the subject line being: SWAG Mailing List Confirmation!)

This is just a difference between email clients. There's nothing you can do about it.
Separately, you are using a very old version of PHPMailer (so update it), and you can remove these lines from your script as they're not doing anything:
$mail->IsMail(); //This is the default, so does nothing
$mail->ContentType="text/HTML"; //Calling isHTML does this for you, but correctly
$mail->ClearAddresses(); //This does nothing as the instance is destroyed when it goes out of scope

Related

recipient receives same mail twice while sending mail in yii 1.1

I am trying to send mail to recipient one at a time.My code is like this:
$message = new YiiMailMessage;
$message->view = "mail";
$params = array('sendEmail'=>$values);
$message->subject = $values['subject'];
$message->setBody($params, 'text/html');
$message->from =$values['email_from'] ;
$message->addTo($values['email_to']);
if(Yii::app()->mail->send($message)){
Yii::app()->user->setFlash('success','Success sending email. ');
$this->redirect(array('mail/admin'));
}else{
Yii::app()->user->setFlash('error','Error while sending email. ');
}
Mail is received by recipient but same mail is received twice.
Maybe you are using a create action to notify the user each time a new record is created. Verify Yii::app()->mail->send($message) appears one time in your action, for example:
public function actionCreate()
{
$model= new MyModel;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['SomeForm']))
{
$model->attributes=$_POST['SomeForm'];
if($model->validate()){
if($model->save()){
$message = new YiiMailMessage;
$message->setBody('<h1>mets-blog.com</h1>','text/html');
$message->subject = 'Service';
$message->addTo('mets#blog.com');
$message->from = 'your#email.com' you want
Yii::app()->mail->send($message);
$this->redirect(array('view','id'=>$model->id));
}
}
}
$this->render('create',array(
'model'=>$model,
));
}
maybe you are calling your action twice in your controller by render your view.

Why might php mail sent but not received unless I manually call the script?

Why might php mail not be received in the second case where twilio is calling the page? Are there characters that might be returned from the api that make the email undeliverable?
1) If I type the URL into the broweser, it attempts to make a wav file in my recordings folder and I get the emails and text messages to all the recipients. The output below is served and the "1" indicates the message was sent.
2) If twilio calls the page and handles the xml, the actual message is recorded to my server, and the output below is served to twilio (which I have verified in my account), but no one receives the email or text. The body of the xml still shows "1" after good bye, indicating the message was sent.
My script:
<?php
date_default_timezone_set('America/New_York');
//copy the remote wav file to my server
$recording = file_get_contents($_REQUEST['RecordingUrl']);
$name = "recordings/".str_replace("+","",$_REQUEST['Caller'])."-".date('Y-m-d-G-i-s',time()).".wav";
$fh = fopen("../".$name, 'w') or die("can't open file");
$stringData = $recording;
fwrite($fh, $stringData);
fclose($fh);
//email the people that need to get the message
$to = "email1#yahoo.com";
$subject = "Voicemail from ".$_REQUEST['From'];
$message = "Click below to listen to your message:\n\r http://domain.com/twilio/".$name;
$from = "email2#domain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$to = "email3#domain.com";
mail($to,$subject,$message,$headers);
$to = "9545555555#messaging.sprintpcs.com";
$sent = mail($to,$subject,$message,$headers);
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<Response>
<Say>Thank you for your message. Good bye.".$sent."</Say>
<Hangup/>
</Response>";
?>
outputs:
<Response>
<Say>Thank you for your message. Good bye.1</Say>
<Hangup/>
</Response>
I just check to see what the contents of each variable in the php mail function are when twilio calls the script to see if there is a character present from a live twilio message. It comes out like this:
$to = 9545555555#messaging.sprintpcs.com
$subject = Voicemail from +19545555555
$message = Click below to listen to your message:
http://domain.com/twilio/recordings/19545555555-2013-10-12-22-57-03.wav
$headers = From:email2#domain.com
If I call the script manually in the browser they are:
$to = 9545555555#messaging.sprintpcs.com
$subject = Voicemail from
$message = Click below to listen to your message:
http://domain.com/twilio/recordings/-2013-10-12-23-04-37.wav
From:email2#domain.com
I tried removing the "+" out of the subject with no success, but when I removed the entire phone number from the subject it works every which way. The emails and texts are delivered appropriately. It makes no sense to me. Maybe its godaddy webhosting messing with my life again.
Perhaps the from string has bad characters that ruin the mail() call, but echo transparently. Try cleaning your string before putting it into mail().
Something like:
$subject= preg_replace("/[^a-zA-Z0-9]+/", "", $_REQUEST['From']);

how do i send an email through joomla

I have a system so folks can register for a class through my Joomla site (I believe it's 3.0). But from there, I would like to send folks an email filling variables from the registration. So something like:
Dear (name), thank you for registering for (class).
This is to remind you your class is tomorrow, (date), at (place).
I believe for the registration, the system uses authorize.net
How can I accomplish this?
Thanks for the help!!
You can use JFactory:getMailer like suggested in the following post. I'm copying here his code example (modified it a bit):
$subject = "Here is the subject of your message.";
$body = "Here is the body of your message.";
$user = JFactory::getUser();
$to = $user->email;
$from = array("me#mydomain.com", "Brian Edgerton");
# Invoke JMail Class
$mailer = JFactory::getMailer();
# Set sender array so that my name will show up neatly in your inbox
$mailer->setSender($from);
# Add a recipient -- this can be a single address (string) or an array of addresses
$mailer->addRecipient($to);
$mailer->setSubject($subject);
$mailer->setBody($body);
# If you would like to send as HTML, include this line; otherwise, leave it out
$mailer->isHTML();
# Send once you have set all of your options
$mailer->send();
That's all there is to it for sending a simple email. If you would like to add carbon copy recipients, include the following before sending the email:
# Add a blind carbon copy
$mailer->addBCC("blindcopy#yourdomain.com");
Another alternative is using JMail::sendMail: http://docs.joomla.org/API17:JMail::sendMail
Fetch the Mail Object:
`$mailer = JFactory::getMailer();`
Set a Sender
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
$mailer->setSender($sender);
Recipient
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
Create the Mail
$body = 'Body Text';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
Sending the Mail
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
https://docs.joomla.org/Sending_email_from_extensions

How do I AddAddress automatically in PHPmailer from form php info?

This has got to be a simple one, but I've been searching all over and nothing seems relevant to my problem: or i'm not able to interpret advice for others adequately.
I'm getting the error "You must provide at least one recipient email address. Message could not be sent."
If I put a specific email address in 'AddAddress' field the message is sent. I want to have an email sent to the user who has submitted their form as an automatic email response thanking user for registering... Thus the ($_POST['email']) in the 'AddAddress' field. This works in Mail() php function. Why not PHP MAiler? What am I missing?
Here is my code with sensitive bits taken out (Relevant bit - I think - in bold):
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$email=$_POST['email'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(email,) VALUES('$email',)";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
}
else {
echo "ERROR";
}
?>
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost"; // specify main and backup server
$mail->SMTPAuth = false; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->From = "";
$mail->FromName = "";
**$mail->AddAddress = ($_POST['email']);**
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "";
$mail->Body = "";
$mail->AltBody = "";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
<?php
// close connection
mysql_close();
?>
Many thanks in advance for your advice. Hopefully this will help others too...
Ed
Simple one... just change this line
$mail->AddAddress = ($_POST['email']);
to this:
$mail->AddAddress($_POST['email']);
as it is a method, as opposed to a variable, on the class! :)
there are some good examples you can use on the PHPMailer GitHub

PHP mail to variable

I've searched and searched for something similar, but i think i'm not doing it right. So i will ask a question. This is very basic. My problem is as follows:
I have a multi-page form, consisting of 4 pages + 1 preview page. On the preview page, upon submitting i want the entire form data to be sent to 2 different mail adresses. One standard, and the other one, the one that the user has submitted.
So i have:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'mail#company.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "yourname#yourwebsite.com, $email /n";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
?>
How should I insert the submitted $email variable in order for it to work?
Remove the \n
$to = 'yourname#yourwebsite.com,' . $visitor_email;
According to the mail() function documentation the $to parameter will take a comma-separated list of addresses as you have attempted, but should have no line break at the end.
Also, your variable is $visitor_email, rather than $email.
$to = "yourname#yourwebsite.com, $visitor_email";
You might also consider adding the visitor's email as a CC or BCC rather than the TO address. In that case, add it as a CC or BCC header (separated by \r\n), but you need to be cautious to be sure that the address is an email address and contains no line break characters which could be used for header injection.
// The From should be an email address
$headers = "From: company#example.com\r\n";
$headers .= "CC: $visitor_email;