Why my html code also display when i send email? - 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

Related

PHP string help mail

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);

php mail with PDF attachment header causes to go into just mail

I have a webform that generates a PDF which is emailed to me upon submission but the email keeps getting filtered to the spam for folder. I suspect that the something is wrong in the email header but not sure what it could be.
Any help is appreciated.
The following is a snippet...
// send by email
$fileatt = '../pdfs/'.$filename;
$fileatt_type = mime_content_type_manual($fileatt); // File Type "application/pdf"
$fileatt_name = $filename; // Filename that will be used for the file as the attachment
$email_from = "auth#mysite.com"; // Who the email is from
$email_subject = "Auth Report"; // The Subject of the email
//$email_to = "info#mysite.com";
$email_to = "info#mysite.com";
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
If you add the sender of the email, which is auth#mysite.com for your case, as a new contact to the address book of your email client, then the email won't probably be marked as spam as it comes from a member of your contact address book.

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);

Warning: mail() [function.mail]: SMTP server response: 552 5.7.0 DATA header size exceeds maximum permitted

I'm Beau from Fijura Web Design in Perth, Western Australia.
Having an issue on my server. I am trying to create a script that will send an email with an attachment and whenever I try to run the script I get the following response:
Warning: mail() [function.mail]: SMTP server response: 552 5.7.0 DATA
header size exceeds maximum permitted in E:\folder\folder\_api\sendreports.php
on line 52
The code I am using is a proven script as I use it on shared Linux servers at our data centre but I cannot get it to work on my Windows server. The script I use is:
include "../reports/rankings.php"; //this is my FPDF attachment
$to=$array['email']; //this pulls an email address from an array output by my MySQL Server
$from="Fijura SEO<seo#fijura.com.au>";
$subject="SEO Ranking Report - New Data ".date("d M Y");
$message="New SEO data is available. See attached report.";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "SEO-Ranking-Report-".date("d-M-Y").".pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; //If I remove all $header information from this line down the email sends fine, just without the attachment.
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
mail($to,$subject,$message,$headers) or die("Failed");
The attached PDF should look like this: Sample SEO Rankings Report
also the php.ini file is configured as follows:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.bigpond.com
; http://php.net/smtp-port
smtp_port = 25
I guess your email will be come back.I have 3 recommendation:
1. Read careful The Spamhaus Project that it cause your emails aren't spam.
2. create an *.eml and send it via socket. your .eml contain of your email such as type of header,body, attachment and etc.
3. don't use mail() function of php language, because some of shared hosting ban it.

How do I set the name of an email sender via PHP

So I want the from field when an email is opened to be something like
"Jack Sparrow Via somesite" as opposed to an explicit email address.
I wondering how to set this in PHP's mail() function?
You can accomplish this by using basic headers.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Jack Sparrow <jsparrow#blackpearl.com>' . PHP_EOL .
'Reply-To: Jack Sparrow <jsparrow#blackpearl.com>' . PHP_EOL .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
You have to set your headers:
$to = "Someone#email.com";
$header = "FROM: Jack Sparrow <some#site.com>\r\n";
$message = "Your message here.";
$subject = "Your subject";
mail($to,$subject,$message,$header) or die();
just use like this
$headers .= 'From: [Name of the person]'.'<'. $this->from .'>'. "\n";
in Header Section.
If you use PHP Mailer from GitHub, then you do it by:
$mail->SetFrom("info#mibckerala.org", "MIBC");
$to = "Someone#email.com";
$message = "Your message here.";
$subject = "Your subject";
mail($to,$subject,$message,$header, '-f some#site.com -F "Jack Sparrow"') or die();
Just add the -f parameter to provide the sender's email and -F parameter to provide the sender's name to the mail(), all as a string.
Note: double quotes around "Jack Sparrow"
Assuming that you are using sendmail on a Linux machine:
You can find more detailed information by typing "man sendmail" in your shell.
I am not sure exactly what you mean, but as you can see on PHP.net mail function.
To add the name to the from section you need to send this in the headers.
From:Name<email#example.com>