Problems using mail() to send answers to an html form

the mail() function

Moderators: macek, egami, gesf

sdrandom8
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Oct 02, 2011 1:31 am

Problems using mail() to send answers to an html form

Postby sdrandom8 » Sun Oct 02, 2011 2:04 am

Hi,

I'm very new to php and html forms, but I just want a simple form that sends an email from one of my gmail addresses to my other, with a person's email, name and comments. Below is the code I have tried, made from little bits of code from the web, but it doesn't work - at least not in my browser, G Chrome 14.0. When I press "Submit" I just see the php code, it doesn't run, it doesn't send an email.

I'm not sure if this will help, but both email addresses are gmail

HTML Form:

Code: Select all

<form name="input" action="sendMail.php" method="get">
Your email: <br/><input type="text" name="email" /><br/>
Your name: <br/><input type="text" name="message" /><br/>
Comments/questions: <br/><textarea cols="40" rows="5" name="comments">
</textarea><br/>
<input type="submit" value="Submit" />

PHP Code:

Code: Select all

<? PHP
$message1 = $_GET['email'];
$message2 = $_GET['message'] ;
$message3 = $_GET['comments'];
$message = "Email: $message1\nLanguage: \nComments / Questions: $message3";
$email = "my-other-email-address@gmail.com";

mail( "my-email-address@gmail.com", "Language suggestion:  $message2", $message, "From: $email" );

print "Your form has been submitted, click ";
print "<a href=\"http://www.mywebsite.com\">here</a>" ;
print " to return to the main page";
?>

KelvinLee18
New php-forum User
New php-forum User
Posts: 36
Joined: Sat Oct 01, 2011 4:44 pm

Re: Problems using mail() to send answers to an html form

Postby KelvinLee18 » Sun Oct 02, 2011 3:29 am

In order to send mail from your server, you have to setup your PHP configuration file(php.ini) for this specific purpose.

Lookup these things in php.ini file
- sendmail_from
- SMTP

:D

Shiftas
New php-forum User
New php-forum User
Posts: 7
Joined: Mon Oct 03, 2011 3:15 am
Location: Lithuania
Contact:

Re: Problems using mail() to send answers to an html form

Postby Shiftas » Mon Oct 03, 2011 4:46 am

You could also use something like phpmailer or swiftmailer. There are nice tutorials how to set them up and they are quite easy to use.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest

cron