0

I brought a shared sever, and got a little storage space. When i run my web site, the mail function works perfectly. Mail has been sent with subject and message to all receivers. But the mail which is sent mentioned "From : ". Headers what i included are not working. I want to send with my headers Eg:Form: [email protected] . How can i do it?

<?php
$output="";
if(isset($_POST['submit']) && !empty($_POST['message']))
{
    $sub=$_POST['subject'];
    $msg=$_POST['message'];
    $sql = "select email from login where status='client'";
    $query = mysqli_query($con,$sql);

    $to=array();

    while($row = mysqli_fetch_array($query))
    {
        $to[] = $row['email'];
        $parts = implode(',',$to);
        $headers = 'From: [email protected];';
        $headers .= 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $subject = $sub;
        $content = $msg;    
    }

    if(mail($parts,$subject,$content,$headers))
    {
        $output="mail sent";
    }
    else
    {
        $output="Error in connection, Mail could not be sent. Please try again";
    }

}
?>

2 Answers 2

1

You need to manually specify the headers, this is the function I use and it delivers to pretty much every provider beautifully. The headers you want are From: and Reply-To: and I also advise the X-Mailer follows what is seen here, I found it years ago via SO as well.

<?php
    $to      = "[email protected]";                                
    $headers = 'From: My Name <[email protected]>' . "\r\n" .
               'Reply-To: My Name <[email protected]>' . "\r\n" .
               'X-Mailer: PHP/' . phpversion() . "\r\n" .
               'Content-type: text/html; charset=iso-8859-1';
    $subject = "My subject line here";
    $message = 'Message HTML and Content Here.';

    if(mail($to, $subject, $message, $headers)){
        // Success Here
    }else{
        // Failed Here
    }
?>

I am not 100% certain it will work for you as I am on a dedicated machine, having said that - I do use it on multiple domains and have never messed with my Apache or php configuration in relation to mail settings.

Read More about the Mail function in PHP: http://php.net/manual/en/function.mail.php

Sign up to request clarification or add additional context in comments.

1 Comment

BCC is simply another line within the headers variable, except instead of 'From: ' you will put 'Bcc: ' - It is of my understanding that these are CASE sensitive. CC is the same 'Cc: ' (I have updated my answer to include a link to the PHP documentation on the matter.
0

You can try below code, just ripped from php.net

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

Off topic but good to use PHPMailer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.