Submitting html forms to email problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RisTar
Forum Newbie
Posts: 2
Joined: Sat Sep 20, 2008 7:16 am

Submitting html forms to email problem

Post 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);
?>
 
adroit
Forum Commoner
Posts: 37
Joined: Fri Aug 08, 2008 1:25 am
Location: India
Contact:

Re: Submitting html forms to email problem

Post by adroit »

Hi Friend,

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

with

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

Regards
RisTar
Forum Newbie
Posts: 2
Joined: Sat Sep 20, 2008 7:16 am

Re: Submitting html forms to email problem

Post by RisTar »

Its still not working.
What else can it be ?

Thanks for your reply adroit
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Submitting html forms to email problem

Post by jayshields »

Try

Code: Select all

$headers = "From: " . $email . "\r\n";
If that fails, try sending an email using a library like SwiftMailer.
adroit
Forum Commoner
Posts: 37
Joined: Fri Aug 08, 2008 1:25 am
Location: India
Contact:

Re: Submitting html forms to email problem

Post by adroit »

It is working. I have just test on my live server with my gmail id.
Post Reply