Page 1 of 1

Submitting html forms to email problem

Posted: Sat Sep 20, 2008 7:19 am
by RisTar
Hi , i just started with php .
Im trying to submit an html form to an email address but the code is not working
for some reason . I already uploaded it to the server , but i cant figure out what is the problem with the code

HTML

Code: Select all

 
                <form action="submitform.php" method="post">
                    <div id="contactUsForm">Name:   <br>
                    <input type="text" name="nameTextBox" id="nameTextBox" /></p>
                    <p>Subject:<br>
                    <input type="text" name="subTextBox" id="subTextBox" /></p>
                    <p>Email: <br>
                    <input type="text" name="emailTextBox" id="emailTextBox" /></p>
                    <p>Message:<br>
                    <textarea name="msgTextBox" cols="50" rows="7" id="msgTextBox"></textarea>
                    <input type="submit" name="submit" value="submit" id="submitBtn" />
                    <input type="submit" name="clearForm" value="clear form" id="clearFormBtn" />
                    </p>
                    </div>
                </form> 
 
PHP (submitform.php)

Code: Select all

 
<?php
    $webmaster = "shlomi.nahari@hotmail.com";
    $name = $_POST ['nameTextBox'];
    $subject = $_POST ['subTextBox'];
    $email = $_POST ['emailTextBox'];
    $message = $_POST ['msgTextBox'];
    $emailmessage = "Name: " . $name .  "/n" . $message;
    $headers = "From: {$email}";
    mail ($webmaster, $subject, $emailmessage, $headers);
?>
 

Re: Submitting html forms to email problem

Posted: Sat Sep 20, 2008 7:29 am
by adroit
Hi Friend,

Replace your this code
$headers = "From: {$email}";

with

$headers = 'From: '.$email.' <'.$email.'>';

Regards

Re: Submitting html forms to email problem

Posted: Sat Sep 20, 2008 7:43 am
by RisTar
Its still not working.
What else can it be ?

Thanks for your reply adroit

Re: Submitting html forms to email problem

Posted: Sat Sep 20, 2008 7:50 am
by jayshields
Try

Code: Select all

$headers = "From: " . $email . "\r\n";
If that fails, try sending an email using a library like SwiftMailer.

Re: Submitting html forms to email problem

Posted: Sat Sep 20, 2008 7:51 am
by adroit
It is working. I have just test on my live server with my gmail id.