Jump to content

Recommended Posts

Contact Form.php

 

 

Please can someone help me on this as i have tried to implement the code given by hostgatore with no avail

as i have set up this php contact form on my server as is below, with my hot-mail account it works fine but would like it to have a different header instead of the server name header, how can i do this. snap shot taken,

A link of hostgatore faq suggestions http://support.hostgator.com/articles/php-email-from-header does not work when added,. can somone please fix and help me on this 3 days of no sleep for something simple i guess,

 

 

Thanx in advance

 

 

Contact Form.php

 

<?php

    $to = 'no-reply@hotmail.com';  // please change this email id
    
    $errors = array();
    // print_r($_POST);

    // Check if name has been entered
    if (!isset($_POST['name'])) {
        $errors['name'] = 'Please enter your name';
    }
    
    // Check if email has been entered and is valid
    if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errors['email'] = 'Please enter a valid email address';
    }
    
    //Check if message has been entered
    if (!isset($_POST['message'])) {
        $errors['message'] = 'Please enter your message';
    }

    $errorOutput = '';

    if(!empty($errors)){

        $errorOutput .= '<div class="alert alert-danger alert-dismissible" role="alert">';
         $errorOutput .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';

        $errorOutput  .= '<ul>';

        foreach ($errors as $key => $value) {
            $errorOutput .= '<li>'.$value.'</li>';
        }

        $errorOutput .= '</ul>';
        $errorOutput .= '</div>';

        echo $errorOutput;
        die();
    }

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = $email;
    $subject = 'Contact Form : 3GS MESSANGER';
    
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";


    //send the email
    $result = '';
    if (mail ($to, $subject, $body)) {
        $result .= '<div class="alert alert-success alert-dismissible" role="alert">';
         $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
        $result .= 'Thank You! Feedback in 24 Hours';
        $result .= '</div>';

        echo $result;
        die();
    }

    $result = '';
    $result .= '<div class="alert alert-danger alert-dismissible" role="alert">';
    $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
    $result .= 'Something bad happend during sending this message. Please try again later';
    $result .= '</div>';

    echo $result;
    die();


?>
  

post-202663-0-10983500-1476745154_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/302352-contact-formphp/
Share on other sites

Set headers, 4th parameter of mail() function

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: TO_NAME <TO_MAIL>' . "\r\n";
$headers .= 'From: FROM_NAME <FROM_MAIL>' . "\r\n";
$headers .= 'Cc: CC_MAIL' . "\r\n"; 
$headers .= 'Bcc: BCC_MAIL' . "\r\n";
Link to comment
https://forums.phpfreaks.com/topic/302352-contact-formphp/#findComment-1538378
Share on other sites

Good developers turn on php error checking when doing their development. Try it.

 

BTW - you actually didn't say what was NOT working. I can only assume that your email is not being sent. The headers suggestion could solve that, but if you had read the PHP manual that would have been apparent.

Link to comment
https://forums.phpfreaks.com/topic/302352-contact-formphp/#findComment-1538379
Share on other sites

Hi Pravin

 

Thank you for taking your time to resolve this issue, but have done as you said with no change,

sending the code as  updated i hoped i did  Ok with no success. i am actually new at all this trying to set a contact form .

 

 

<?php

 

    $to = 'no-reply@hotmail.com';  // please change this email id

    

    $errors = array();

    // print_r($_POST);

 

    // Check if name has been entered

    if (!isset($_POST['name'])) {

        $errors['name'] = 'Please enter your name';

    }

    

    // Check if email has been entered and is valid

    if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {

        $errors['email'] = 'Please enter a valid email address';

    }

    

    //Check if message has been entered

    if (!isset($_POST['message'])) {

        $errors['message'] = 'Please enter your message';

    }

 

    $errorOutput = '';

 

    if(!empty($errors)){

 

        $errorOutput .= '<div class="alert alert-danger alert-dismissible" role="alert">';

         $errorOutput .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';

 

        $errorOutput  .= '<ul>';

 

        foreach ($errors as $key => $value) {

            $errorOutput .= '<li>'.$value.'</li>';

        }

 

        $errorOutput .= '</ul>';

        $errorOutput .= '</div>';

 

        echo $errorOutput;

        die();

    }

 

 

    $name = $_POST['name'];

    $email = $_POST['email'];

    $message = $_POST['message'];

    $from = $email;

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

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

// Additional headers

$headers .= 'To: Test <no-reply@hotmail.com>' . "\r\n";

$headers .= 'From: Test <no-reply@hotmail.com>' . "\r\n";

$headers .= 'Cc: no-reply@hotmail.com' . "\r\n";

$headers .= 'Bcc: no-reply@hotmail.com' . "\r\n";

        $subject = 'Contact Form : MESSANGER';

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

 

 

    //send the email

    $result = '';

    if (mail ($to, $subject, $body)) {

        $result .= '<div class="alert alert-success alert-dismissible" role="alert">';

         $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';

        $result .= 'Thank You! Feedback in 24 Hours';

        $result .= '</div>';

 

        echo $result;

        die();

    }

 

    $result = '';

    $result .= '<div class="alert alert-danger alert-dismissible" role="alert">';

    $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';

    $result .= 'Something bad happend during sending this message. Please try again later';

    $result .= '</div>';

 

    echo $result;

    die();

 

 

?>

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Set headers, 4th parameter of mail() function

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: TO_NAME <TO_MAIL>' . "\r\n";
$headers .= 'From: FROM_NAME <FROM_MAIL>' . "\r\n";
$headers .= 'Cc: CC_MAIL' . "\r\n"; 
$headers .= 'Bcc: BCC_MAIL' . "\r\n";
Link to comment
https://forums.phpfreaks.com/topic/302352-contact-formphp/#findComment-1538412
Share on other sites

Hi Giner

 

Yes i am reeving e-mails it all works fine but i would like the header to change as it sends the server side header would like

a customized name header snapshot was attached in previous message. Thank you for taking your time on this.

 

<?php

    $to = 'no-reply@hotmail.com';  // please change this email id
    
    $errors = array();
    // print_r($_POST);

    // Check if name has been entered
    if (!isset($_POST['name'])) {
        $errors['name'] = 'Please enter your name';
    }
    
    // Check if email has been entered and is valid
    if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errors['email'] = 'Please enter a valid email address';
    }
    
    //Check if message has been entered
    if (!isset($_POST['message'])) {
        $errors['message'] = 'Please enter your message';
    }

    $errorOutput = '';

    if(!empty($errors)){

        $errorOutput .= '<div class="alert alert-danger alert-dismissible" role="alert">';
         $errorOutput .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';

        $errorOutput  .= '<ul>';

        foreach ($errors as $key => $value) {
            $errorOutput .= '<li>'.$value.'</li>';
        }

        $errorOutput .= '</ul>';
        $errorOutput .= '</div>';

        echo $errorOutput;
        die();
    }


    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = $email;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Test <no-reply@hotmail.com>' . "\r\n";
$headers .= 'From: Test <no-reply@hotmail.com>' . "\r\n";
$headers .= 'Cc: no-reply@hotmail.com' . "\r\n";
$headers .= 'Bcc: no-reply@hotmail.com' . "\r\n";
        $subject = 'Contact Form :MESSANGER';
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";


    //send the email
    $result = '';
    if (mail ($to, $subject, $body)) {
        $result .= '<div class="alert alert-success alert-dismissible" role="alert">';
         $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
        $result .= 'Thank You! Feedback in 24 Hours';
        $result .= '</div>';

        echo $result;
        die();
    }

    $result = '';
    $result .= '<div class="alert alert-danger alert-dismissible" role="alert">';
    $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
    $result .= 'Something bad happend during sending this message. Please try again later';
    $result .= '</div>';

    echo $result;
    die();


?>

 

Good developers turn on php error checking when doing their development. Try it.

BTW - you actually didn't say what was NOT working. I can only assume that your email is not being sent. The headers suggestion could solve that, but if you had read the PHP manual that would have been apparent.

Link to comment
https://forums.phpfreaks.com/topic/302352-contact-formphp/#findComment-1538413
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.