1

Here is my code

$form_message .= "Application_Comments" . "\r\n";
ini_set('your_email', 'testsupport@example.com');
$to = "xyz@gmail.com";
$subject = "Collaboration";
$your_email = 'testsupport@example.com';
$headers  = "From: $your_email" . "\r\n";
$headers .= "Cc:abc@yahoo.com,efg@gmail.com"."\r\n";
$headers .= "Reply-To: $your_email" . "\r\n";

if(mail($to,$subject,$form_message,$headers))
{
    echo " Delete Mail Sent Successfully";
}
else
{
    echo "Delete Mail not sent";
}

if I execute above code I am not receiving any mail even 'To' mail is also not getting.

If I use one mail address in cc I am getting mail, but 'To' mail was not received

can any one help me on this?

Bob The Janitor
  • 20,292
  • 10
  • 49
  • 72
R9102
  • 687
  • 1
  • 9
  • 32

1 Answers1

0

You should consider using the popular PHPMailer class to handle email needs in PHP. It makes sending emails with multiple TOs, CCs, BCCs and REPLY-TOs easily achieved. It even let's you easily add attachments to your emails. Download the ZIP from Github, and extract it to the directory it will be used in.

<?php
require '/path/to/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>
CloudBranch
  • 1,434
  • 3
  • 18
  • 23
  • 3
    No matter how relevant, a statement of "use this addon instead" does not really answer the fundamental question raised about a native PHP function. `PHPMailer` is awesome but it's an additional, an addon and so this guide to using it does nothing for solving the original issue raised. (and no I didn't down vote you) – Martin Aug 16 '16 at 17:28
  • 2
    I'll upvote you. Everyone should really stop using the php `mail()` function. – Nick Aug 16 '16 at 17:37
  • If this was helpful please select as the answer. I appreciate the detailed response. I'll answer questions differently next time. @Martin I also totally agree with Nick. – CloudBranch Aug 16 '16 at 18:10
  • @JoshuaWhalen trying to bend the OP's arm into accepting this as an answer is risible. – Progrock Aug 16 '16 at 21:20
  • I'm glad you find it humorous. @Progrock – CloudBranch Aug 16 '16 at 22:34