-3

How to send mail in php $from1="from@gmail.com"; $headers = 'MIME-Version: 1.0' . "\r\n; $headers.= 'Content-type: text/html; charset=utf-8' .\r\n; $headers.=From: Newslatter ' .$from1.\r\n; $headers .= Reply-To: '.$from1.\r\n; $headers .=Return-Path:'.$from1.\r\n; $headers .= CC:.$CCMAIL1.\r\n; $headers .= 'BCC: '.$BCCMAIL.\r\n;

if(mail($to,$subject,$message,$headers)){
    return true;
}
else{
    return false;
}
debasish
  • 735
  • 1
  • 9
  • 14

3 Answers3

0

You should never use the backtick (`) to denote a string. Double quotes (") are needed for strings containing PHP variable and stuff like \n and \r, while single quotes (') work for everything else.

This is wrong:

$headers  = 'MIME-Version: 1.0' . "\r\n`;

and this is right:

$headers  = 'MIME-Version: 1.0' . "\r\n";

or this:

$headers  = "MIME-Version: 1.0 \r\n";

etc. Make sure you clear all of your code like this.

Double quotes allow you to avoid concat, so this:

echo "The value of my_var is $my_var";

is the same as:

echo 'The value of my_var is ' . $my_var;

But backticks never work for this purpose and will throw errors.

Other that than, just make sure you've configured your SMTP settings in your php.ini file and you should be good to go.

Shomz
  • 37,421
  • 4
  • 57
  • 85
0

Depending on which accounts you plan on sending and how your server is configured, if you're using the PHP mail function you may find that your email is not delivered. I found this to be the case, Gmail was filtering my mails sent via PHP Mail.

You can get around this problem by using the SMTP PHP Mail class:

https://github.com/Synchro/PHPMailer

You just need to know the SMTP mail server, user and password as provided by your email host.

Alan.

Alan A
  • 2,557
  • 6
  • 32
  • 54
0

You should only use simple quotas: " and '. Like this:

$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type: text/html; charset=utf-8' . '\r\n';
$headers .= 'From: Newslatter ' .$from1.'\r\n';
$headers .= 'Reply-To: '.$from1.'\r\n';
$headers .= 'Return-Path:'.$from1.'\r\n';
$headers .= 'CC: '.$from1.'\r\n';
$headers .= 'BCC: '.$from1.'\r\n';

if(mail($to,$subject,$message,$headers)){
    return true;
}
else{
    return false;
}

And you should set the $to, $subject and $message too.

You can find more help about php mail function here.

And about setting variables or using quotas here.

artur99
  • 818
  • 6
  • 18