Saturday, September 12, 2015

send mail useful arguments

<?php
$mail_dataArr = array(
  'sender_name' => 'My Name',
  'sender_mail' => 'me@example.com',
  'title' => 'My subject',
  'body' => 'My body',
);

test_sendmail('test@example.com', $mail_dataArr);

function test_sendmail($receiver_mail, $mail_dataArr) {
  $FROM = $mail_dataArr['sender_name'] . '<' . $mail_dataArr['sender_mail'] . '>';

  $headers = '';
  $headers .= 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
  $headers .= 'From: ' . $FROM . "\r\n";
  //$headers .= !empty($REPLY_TO) ? 'Reply-To: ' . $REPLY_TO . "\r\n" : '';
  //$headers .= 'Bcc: ' . $BCC_LIST . PHP_EOL;
  $headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;

  mail($receiver_mail, $mail_dataArr['title'], $mail_dataArr['body'], $headers, "-odb -f " . $mail_dataArr['sender_mail']);
}
?>

No comments: