SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2012
    Location
    N.Ireland
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Configure contact form on live server using php

    I need to adjust the settings of a contact form so that the format of the message that a AJAX/PHP script presents to the SMTP service works.

    The critical part is the 'From field' it needs to show 'noreply@domain.org'

    The message should output :

    -----Original Message-----
    From: noreply@domain.org [mailto:noreply@domain.org]
    Sent: 01 March 2013 11:46
    To: $name
    Subject: $message.
    The format of the message presents to the SMTP service is important.

    My currrent php mail process script is;
    PHP Code:
    <?php
    /*
    Credits: Bit Repository
    URL: http://www.bitrepository.com/
    */

    include dirname(dirname(__FILE__)).'/config.php';

    error_reporting (E_ALL E_NOTICE);

    $post = (!empty($_POST)) ? true false;

    if(
    $post)
    {
    include 
    'functions.php';

    $headers 'From: name <noreply@domain.org>' .

    $name stripslashes($_POST['name']);
    $email trim($_POST['email']);
    //$subject = stripslashes($_POST['subject']);
    $message stripslashes($_POST['message']);

    $error '';

    // Check name

    if(!$name)
    {
    $error .= 'Please enter your name.<br />';
    }

    // Check email

    if(!$email)
    {
    $error .= 'Please enter an e-mail address.<br />';
    }

    if(
    $email && !ValidateEmail($email))
    {
    $error .= 'Please enter a valid e-mail address.<br />';
    }

    // Check message (length)

    if(!$message || strlen($message) < 15)
    {
    $error .= "Please enter your message. It should have at least 15 characters.<br />";
    }

    if(!
    $error)
    {
    $mail mail(WEBMASTER_EMAIL"$headers",
         
    "From: ".$name." <".$email.">\r\n"
        
    ."Reply-To: ".$email."\r\n"
        
    ."Message: ".$message."\r\n");

    if(
    $mail)
    {
    echo 
    'OK';


    }
    else
    {
    echo 
    '<div class="notification_error">'.$error.'</div>';
    }

    }
    ?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by manual
    bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
    you have them in the wrong order it seems:
    PHP Code:
    $subject "This is not spam, please read this email";

    $mail mail(WEBMASTER_EMAIL
         
    $subject,
         
    "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n"  ."Message: ".$message."\r\n"
        
    $headers); 
    .. by the looks of things ...

  3. #3
    SitePoint Zealot
    Join Date
    May 2012
    Location
    N.Ireland
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    you have them in the wrong order it seems:
    PHP Code:
    $subject "This is not spam, please read this email";

    $mail mail(WEBMASTER_EMAIL
         
    $subject,
         
    "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n"  ."Message: ".$message."\r\n"
        
    $headers); 
    .. by the looks of things ...
    Okay i'm fine on this yet how will it address my issue in making sure that the noreply@domain.org is entered into the From field to allow the SMTP to process?

    Current code is now -

    Code:
    <?php
    /*
    Credits: Bit Repository
    URL: http://www.bitrepository.com/
    */
    
    include dirname(dirname(__FILE__)).'/config.php';
    
    error_reporting (E_ALL ^ E_NOTICE);
    
    $post = (!empty($_POST)) ? true : false;
    
    if($post)
    {
    include 'functions.php';
    
    $headers = 'From: CYPSP Website <noreply@domain.org>' .
    $name = stripslashes($_POST['name']);
    $email = trim($_POST['email']);
    //$subject = stripslashes($_POST['subject']);
    $message = stripslashes($_POST['message']);
    
    $error = '';
    
    // Check name
    
    if(!$name)
    {
    $error .= 'Please enter your name.<br />';
    }
    
    // Check email
    
    if(!$email)
    {
    $error .= 'Please enter an e-mail address.<br />';
    }
    
    if($email && !ValidateEmail($email))
    {
    $error .= 'Please enter a valid e-mail address.<br />';
    }
    
    // Check message (length)
    
    if(!$message || strlen($message) < 15)
    {
    $error .= "Please enter your message. It should have at least 15 characters.<br />";
    }
    
    if(!$error)
    {
    $subject = "This is not spam, please read this email";
    
    $mail = mail(WEBMASTER_EMAIL, "$subject",
         "From: ".$name." <".$email.">\r\n"
         ."Reply-To: ".$email."\r\n"  
         ."Message: ".$message."\r\n"
         , $headers);  
    
    if($mail)
    {
    echo 'OK';
    } 
    
    }
    else
    {
    echo '<div class="notification_error">'.$error.'</div>';
    }
    
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •