PHP string help mail - email

hi need some help with mailing. I'm trying to insert the content of this variable into a string to send as an email also need to add a newline. Also need to change From header to "Procity" and procitystaff#gmail.com
$claim_msg='Hey $claim_username, \n The donator has cancelled your claimed item, but you got your ' $email_to=$claim_email;
$template=$claim_msg;
$subject= "Claimed item canceled";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1 '.' \r\n';
$headers .= 'From: procitystaff#gmail.com'.' \r\n';
$from='procitystaff#gmail.com';
mail($email_to,$subject,$template,$headers);

You're missing a semi-colon before $email_to which would cause a syntax error.
You're also using single-quotes ' while inserting a php variable printing out Hey $claim_username as opposed to double-quotes " which would print Hey JohnDoe.

The semi-colon was missing at the end of the first line in the code below. Plus, I also used concatenates.
Give this a try. There will be a line break between the username and The donator.
Example:
Hey John,
The donator has cancelled your claimed item, but you got your
$claim_msg='Hey ' . $claim_username . ',' . "<br>\n" . 'The donator has cancelled your claimed item, but you got your';
$email_to=$claim_email;
$template=$claim_msg;
$subject= "Claimed item canceled";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1 '.' \r\n';
$headers .= 'From: Procity <procitystaff#gmail.com>' . "\r\n";
$from='procitystaff#gmail.com';
mail($email_to,$subject,$template,$headers);

Related

Sent email with iCal to outlook with valarm reminder

I am in a situation where I want to send email with iCal attachment to Outlook Calendar and I want to set reminder to 120 minutes before start event.
I send RAW message with iCal(see below).
If recipient opens the message, event is automatically added to outlook calendar, but reminder is set to 15 minutes(default in outlook), even if I set different value in VALARM.
If I use ics file with iCal to import to Outlook Calendar then reminder is set to my value.
I would really appreciate help on this. How to set reminder for event?
$from_name = "<FROM_NAME>";
$from_address = "<FROM_ADDRESS>";
$subject = "Meeting Booking";
$meeting_description = "Here is a brief description of my meeting\n\n";
$meeting_location = "My Office";
$domain = 'domain.com';
$to_name = "<TO_NAME>";
$to_address = "<TO_ADDRESS>";
$meeting_date = "2015-10-21 15:40:00";
$meeting_duration = 3600;
$meeting_stamp = STRTOTIME($meeting_date . " UTC");
$dtstart= GMDATE("Ymd\THis\Z",$meeting_stamp);
$dtend= GMDATE("Ymd\THis\Z",$meeting_stamp+$meeting_duration);
$mime_boundary = "----Meeting Booking----".MD5(TIME());
//Create ICAL Content
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Patient Portal//MyEyeDr.//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($meeting_date)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="America/New_York":'.$dtstart. "\r\n" .
'DTEND;TZID="EAmerica/New_York":'.$dtend. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $meeting_location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM'. "\r\n" .
'ACTION:Display'. "\r\n" .
'DESCRIPTION:'.$meeting_description. "\r\n" .
'SUMMARY:Event Alarm'. "\r\n" .
'TRIGGER:-PT120M'. "\r\n" .
'END:VALARM'. "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message= "To: ".$to_address."\n";
$message.= "From: ".$from_address."\n";
$message.= "Subject: Example SES mail (raw)\n";
$message.= "MIME-Version: 1.0\n";
$message .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$message .= "Content-class: urn:content-classes:calendarmessage\n";
$message.= "\n\n";
$message .= "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear ...,</p>';
$message .= '<p>This is an email message.</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "X-Mailer: Microsoft Office Outlook 15.0\r\n";
$message .= $ical;
I think there is nothing wrong with your code. Most calendar clients will ignore any alarm that is sent along with an invitation. When you think about it, this makes sense: if you invite me, I may want to accept or decline, but you should not dictate when I want to be notified.
On the other hand, when importing, you are making those events your own.
Change METHOD:REQUEST to METHOD:PUBLISH. Also change your other method code at the bottom from method=REQUEST to method=PUBLISH.

How to send PHP mail with HTML formatting [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Everything was working ok until i added HTML. This code is sending the Email with an address as my hosting account username not the email i'm specifying.
$from = "info#site.com";
$headers = "From:" . $from. "\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
After sending, the email is from some weird User#gdfgdfhgfdf bla bla intead of 'info#site.com';
and i assume it's my headers.
Thanks.
You're overwriting your headers, by using the = sign twice in a row, the second line should be
$headers .= 'MIME-Version: 1.0' . "\r\n";
Try including your $from inside the $headers like this.
$from = "info#site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: InfoSite <'.$from.'>'."\r\n"; //<--- Like this.
mail($to,$subject,$message,$headers);

PHP Mail Showing Html Tag

Instead of adding the following Header information it is showing HTML tag in PHP Mail.
$headers = "From: ".$name."<".$email.">\r\n";
$headers .= "Reply To: ".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
Please help me.
Try this,
$subject = 'Mail Subject';
$message = 'Test';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= 'From: ".$name."<".$email.">' . "\r\n";
$headers .= 'Reply-To: ".$email."' . "\r\n";
mail($to, $subject, $message, $headers);
Example from my mail()
$header = "From: Backapp.ru <noreply#backapp.ru>\r\nContent-type: text/html; charset=utf-8";
The basic usage of mail() function with headers is:
<?php
$to = "you#local.com";
$subject = "My email test.";
$message = "Hello";
$headers = "From: myplace#local.com\r\n";
$headers .= "Reply-To: myplace2#local.com\r\n";
$headers .= "Return-Path: myplace#local.com\r\n";
$headers .= "CC: sombodyelse#local.com\r\n";
$headers .= "BCC: hidden#special.com\r\n";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
You don't send us your output so we don't know wheres the problem.

Change the Return-Path in PHP mail function

Is it possible to change the Return-Path value in emails are sending via mail() function of PHP ?
It's value is 'www-data#mydomain.com' in emails I send in my site and it causes some problems on email delivery failed process. I want to set it to my email address.
Here's the code I have tried:
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\n";
$headers .= "Return-Path: <adminemail#yahoo.com>"."\n";
$headers .= "Errors-To: <adminemail#yahoo.com>"."\n";
// Additional headers
$headers .= "To: email1#yahoo.com <adminemail#yahoo.com>" . "\n";
$headers .= "From: adminemail#yahoo.com <adminemail#yahoo.com>";
// Mail it
mail('email1#yahoo.com', 'test', 'salam', $headers, "f");
You can set reply to & return path into headers as below
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'Return-Path: webmaster#example.com'
OR
as the fifth parameter to adjust the return path
mail($to, $subject, $message, $headers, "-f email#wherever.com");
where email#wherever.com should be replaced by your mail.
The issue is mail format requires headers to use \r\n line endings... not \n, the trick with that is some servers will accept both (convert them for you and it seems to work magically) while others will consider those without \r\n endings to be invalid and basically ignore all your headers. So try instead:
$headers = "MIME-Version: 1.0\r\n".
"Content-type: text/html; charset=utf-8\r\n".
"Return-Path: adminemail#yahoo.com";
mail ("email1#yahoo.com","test","salam",$headers);
By the way, return-path expects an RFC1123 mailbox (without the angle brackets, just the email address) ... not sure why you'd want to set return-path as in your example since it's the same as the from address (so superfluous)
Just define Return-Path
$returnPath = "-fadminemail#yahoo.com"; //-f will do the job
mail('email1#yahoo.com', 'test', 'salam', $headers, $returnPath);

Why my html code also display when i send email?

hi dear this is my code to send email
my message code is this
$to = $email;
$subject = "Activation";
$message = "Your activation key is this " .$key.'<br>'.' click here to activate your acount. here';
$from = "riaz_qadeer90#yahoo.com";
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers))
{
echo "Check your email to activate your acount.";
}
The problem is this when i send email the whole message shown in my inbox with code. why it not show "Click" as an anchore.....
Mail isn't HTML format by default, so it's sending this as plain text. See Example #4 on the PHP page for mail() for sending HTML email. You need to specify the content type for the message headers:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Note the .= operator being used here. You'd be appending this to your existing $headers value. So you'll also want to make sure your existing header is terminated properly:
$headers = "From:" . $from . "\r\n";
You have to check following things:-
1>message content properly it has enclosed with which inverted comma,either ' or ".
2>check your header and additional header information properly concatenate with (.) operator or not.
Most of the time problem arrives in second case.
$headers .= 'To: abc, bcd' . "\r\n";
$headers .= 'From:xyz ' . "\r\n";
Because you must define the header of your e-mail as HTML.
http://www.w3schools.com/php/func_mail_mail.asp