mail header issue in sendmail in CentOs 6 - email

I have setup centOs 6 on rackspace server, and installed Apache PHP & other modules.
I also installed sendmail to use mail() function from PHP, it working, but i am not able to set my own header in mail().
$to = "myemail#gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$from = " Team <my#odomain.com>";
$headers = "From: $from\r\n";
$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
But i getting spam emails with header "Apache apache#server". Header is not setting.
I also tried "-f emailaddress", but not working.
What should i do? I had also try some sendmail configuration but still not solved.
Ritesh

Replace \r\n with \n in the line $headers = "From: $from\r\n";

Related

Mail Sending in TCPDF

I have created a PDF using tcpdf function, then i wants to send it to a mail as attachment. i have used following coding at end of the creation of PDF. But it working in some server, but not working in some other servers
$from = "manikandan#niral.us";
$subject = "test";
$message = $_REQUEST['msg'];
// 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;
// $eol = "\r\n";
// attachment name
$filename = "Yourinvices.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output('Patient'.$invnumserial.'.pdf', 'S');
$attachment = chunk_split(base64_encode($pdfdoc));
// encode data (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Enconding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charsrt=\"iso-8859-1\"".$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
//$headers .= "Content-Type: application/zip; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
if(#mail($to, $subject, $message, $headers))
{
Redirect("../../patient_invoicelist.php?msg=1");
}
else Redirect("../../patient_invoicelist.php?msg=2");
Use PHPMailer to send Emails with Attachments. It will be very easy to send emails with attachments using this library.
Download PHPMailer library from this link. You will also find examples to use this class.
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/
$mail->SetFrom('noreply#test.com', 'test');
$mail->Subject = $subject;
$mail->AddAttachment($Pdf_path_here);
$mail->MsgHTML($body);
$mail->AddAddress($to, "");
if(!$mail->Send())
{
echo "sent";
}
else
{
echo "error";
}

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.

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

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>