email - PHP mail() headers -


i have following headers want pass mail() function:

$headers = "mime-version: 1.0\r\n"; $headers .= "x-mailer: php/" . phpversion()."\r\n"; $headers .= "from:".$sender_email."\r\n"; $headers .= "subject:".$subject."\r\n"; $headers .= "reply-to: ".$sender_email."" . "\r\n"; $headers .= "content-type: multipart/mixed; boundary=".md5('boundary1')."\r\n\r\n";  $headers .= "--".md5('boundary1')."\r\n"; $headers .= "content-type: multipart/alternative;  boundary=".md5('boundary2')."\r\n\r\n";  $headers .= "--".md5('boundary2')."\r\n"; $headers .= "content-type: text/plain; charset=iso-8859-1\r\n\r\n"; $headers .= $message."\r\n\r\n";  $headers .= "--".md5('boundary2')."--\r\n"; $headers .= "--".md5('boundary1')."\r\n"; $headers .= "content-type:  ".$file_type."; "; $headers .= "name=\"".$file_name."\"\r\n"; $headers .= "content-transfer-encoding:base64\r\n"; $headers .= "content-disposition:attachment; "; $headers .= "filename=\"".$file_name."\"\r\n"; $headers .= "x-attachment-id:".rand(1000,9000)."\r\n\r\n"; $headers .= $encoded_content."\r\n"; $headers .= "--".md5('boundary1')."--";   $sentmail = @mail($recipient_email, $subject, $message, $headers); 

since don't require user provide e-mail address, can exclude "from" , reply-to" fields , let server auto-complete values or action result in malformed headers?

the server automatically fill in from line. depending on os, either gets default from header php.ini or username runs php (e.g. www-user@yourdomain.com).

by default there's no reply-to, replies sent from address. header needed when want replies go different address, in case there's no need it.

if no replies wanted let default, common approach put address noreply@yourdomain.com in from line. way, if reply, they'll bounce message saying account doesn't exist.

you're putting message body $headers, isn't right. it's working because put blank line before them -- that's treated separator between headers , message, after sent in body. shouldn't depend on this, lines should sent message argument in mail().

$headers = "mime-version: 1.0\r\n"; $headers .= "x-mailer: php/" . phpversion()."\r\n"; $headers .= "from: noreply@yourdomain.com\r\n"; $headers .= "subject:".$subject."\r\n"; $headers .= "content-type: multipart/mixed; boundary=".md5('boundary1')."\r\n\r\n";  $body= "--".md5('boundary1')."\r\n"; $body .= "content-type: multipart/alternative;  boundary=".md5('boundary2')."\r\n\r\n";  $body .= "--".md5('boundary2')."\r\n"; $body .= "content-type: text/plain; charset=iso-8859-1\r\n\r\n"; $body .= $message."\r\n\r\n";  $body .= "--".md5('boundary2')."--\r\n"; $body .= "--".md5('boundary1')."\r\n"; $body .= "content-type:  ".$file_type."; "; $body .= "name=\"".$file_name."\"\r\n"; $body .= "content-transfer-encoding:base64\r\n"; $body .= "content-disposition:attachment; "; $body .= "filename=\"".$file_name."\"\r\n"; $body .= "x-attachment-id:".rand(1000,9000)."\r\n\r\n"; $body .= $encoded_content."\r\n"; $body .= "--".md5('boundary1')."--";   $sentmail = @mail($recipient_email, $subject, $body, $headers); 

there seems no reason multipart/alternative in first body section, since you're not sending multiple versions of $message.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -