Contact us form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • havealot
    New Member
    • Jul 2015
    • 6

    Contact us form

    I've made a form form (contact us) page , with 3 fields:
    [Email,Subject and Message]
    it's cool for now but what happens is when someone submits the form (send an email), it sends the mail from the host email I uploaded my site on .

    what I want is to receive the message to my gmail accout: xxx@gmail.com, from the email that the user wrote it in the email field: aaa@bbb.ccc , not from my host email which is: xxx@myhost.com .

    ---------------------------------
    this is my part of code:

    Code:
    //my email
    $to = 'xxxx@gmail.com';
    
    //subject
    $subject  = $this->subject;
    
    //message
    $message .= $this->message;
    
    //headers
    $headers  = "From: ";
    $headers .= $this->email;
    $headers .= "\nReply-To: ";
    $headers .= $this->email;
    		
    mail($to, $subject, $message, $headers);
    ------------------------------------------

    I hope you can help me..
    thanks in advance
  • computerfox
    Contributor
    • Mar 2010
    • 276

    #2
    I believe this depends on how the SMTP is configured for PHP.
    You can however still try this code:

    Code:
    require_once "Mail.php";
    
    $from = '<from.gmail.com>';
    $to = '<to.yahoo.com>';
    $subject = 'Hi!';
    $body = "Hi,\n\nHow are you?";
    
    $headers = array(
        'From' => $from,
        'To' => $to,
        'Subject' => $subject
    );
    
    $smtp = Mail::factory('smtp', array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => '465',
            'auth' => true,
            'username' => 'johndoe@gmail.com',
            'password' => 'passwordxxx'
        ));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
        echo('<p>' . $mail->getMessage() . '</p>');
    } else {
        echo('<p>Message successfully sent!</p>');
    }

    Comment

    Working...