help sending php email via a form

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
styler
Forum Newbie
Posts: 2
Joined: Tue Aug 21, 2007 9:55 am

help sending php email via a form

Post by styler »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


this is my first attempt at using php in my web pages and i've been trying to include a simple form section which sends me an email & displays a message on submitting. i just can't get this to work - i just get a blank page in the browser with no message & no email is sent.

please let me know where i'm going wrong.

[b]Form html is as follows:[/b]

[syntax="html"]<form action="process.php" method="post" name="form1" id="form1">
 <textarea name="message" cols="30" rows="5" id="message"></textarea>
 <input type="submit" name="Submit" value="Send Message" />
 </form>
which points to a process.php file with the following code[/syntax]

Code: Select all

<?php

$sender_msg=$_POST['message'];

$to = "dstyler@freeuk.com";

$message = $sender_msg;

if(mail($to, $message) 
{

   echo "<h3>Your message has been successfully sent.</h3>";

   echo "We will reply to you in due course.<br /><br />";

   echo "King regards,<br /> <i>The administration</i>";

}

else 
{

   echo "<h3>Error sending your message.</h3>";

   echo "We apologyse for the error occured.<br />Please try again later or contact the adminitrator using alternative methods. <br />";

   echo "Thank you for your understanding.<br /><br /> <i>The administration</i>";

}

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

You have an error in your code.

Code: Select all

if(mail($to, $message)) // was missing the second )
{ 

Code: Select all

error_reporting(E_ALL); // Always nice to see all your errors
// You should put this at the top of your pages when you are testing them
styler
Forum Newbie
Posts: 2
Joined: Tue Aug 21, 2007 9:55 am

Post by styler »

thanks, although it still doesn't work with second bracket! - is there anything else I'm missing?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

mail() expects 3 parameters, you passed only 2.

Listen to the advice and enable error reporting.
Post Reply