Jump to content

[SOLVED] Sending form input as e-mail using PHP


Fixxer

Recommended Posts

Ive found some obvious errors, now I can send the mail, but the $_POST variables are not being sent, they are just blank.

 

<?php

$sender = $_POST["email"];

$name = $_POST["name"];
$day = $_POST["dd"];
$month = $_POST["mm"];
$year = $_POST["yy"];

$today = date("l, F j, Y, g:i a") ;

$body = "Date: $today \n
Name: $name \n
Date Of Event: $date / $month / $year";

?>

Sending Request...

<?php
mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);
?>

Link to comment
Share on other sites

Your code should be like this, your current code does not send the post value because it sends the mail when the page loads and your post values are blank

 

<?php 

// when user presses submit button
// name of button is submit here.... 
if (isset($_POST['submit']))
{
$sender = $_POST["email"];

$name = $_POST["name"];
$day = $_POST["dd"];
$month = $_POST["mm"];
$year = $_POST["yy"];

$today = date("l, F j, Y, g:i a") ;

$body = "Date: $today \n
Name: $name \n
Date Of Event: $date / $month / $year";

mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);

?>

Link to comment
Share on other sites

Now nothing sends. I guess for some reason the data isnt being passed from page to page. the forms action is to the page with this script, and the method is post.

 

Here is the updated code.

No mail is sent and nothing is written where echo is either.

The page loads up fine though.

 

<?php

if(isset($_POST['submit']))
{
$sender = "TMD-Music.com";

$name = $_POST['name'];
$day = $_POST['dd'];
$month = $_POST['mm'];
$year = $_POST['yy'];

$today = date("l, F j, Y, g:i a") ;

$body ="This message was auto generated by TMD-Music.com on: $today \n
Name: $name \n
Date Of Event: $date / $month / $year";

mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);
}

?>


Your request has been sent. 
<br /> <br />
<a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a>
<br /> <br />

------------------------------------------------------

<php echo $name ; ?>

Link to comment
Share on other sites

contact.php

 

<table bgcolor="white" border="0" align="left" cellpadding="5" width="570">
<tr bgcolor="white">
<td bgcolor="white">

<h3>E-Mail Us</h3>
<br />
<br />

<form name="contact" action="mailer.php?" method="post" enctype="text/plain">

Name: <input type="text" name="name" size="25">

<br />

Date Of Event (dd / mm / yy): <input type="text" name="dd" size="2"> <input type="text" name="mm" size="2"> <input type="text" name="yy" size="2">

<br />

Type Of Party: <input type="text" name="type" size="30">

<br />

Phone Number: <input type="text" name="phone" size="12">

<br /> 

E-Mail Address: <input type="text" name="email" size="25">

<br />

Questions: <textarea name="questions" rows="5" cols="60"></textarea>

<br />
<br />

<input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset" name="reset">

</form>


</td>
</tr>
</table>

 

mailer.php

 

<?php


$sender = "TMD-Music.com";

$name = $_POST['name'];
$date = $_POST['dd'];
$month = $_POST['mm'];
$year = $_POST['yy'];
$type = $_POST['type'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$text = $_POST['text'];

$today = date("l, F j, Y, g:i a") ;

$body ="This message was auto generated by TMD-Music.com on: $today \n
Name: $name \n
Date Of Event: $date / $month / $year" \n
Type Of Event: $type \n
Phone Number: $phone \n
E-Mail: $email \n
Message: $text ";

mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);


?>


Your request has been sent. 
<br /> <br />
<a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a>
<br /> <br />

------------------------------------------------------

<php echo $name ; ?>

Link to comment
Share on other sites

Ok I have my own code. It's purpose is different, but it has the same general script:

$email = $_POST["Email"];
$name = $_POST["Name"]
$tags = $_POST["Tags"]
$date = $_POST["Date"]
$oemail = $_POST["other_emails"]
$to = 'uberpilotdudes@bellsouth.net,$email';
$subject = 'Application for Joining';
$from = 'From: $email';
$current = date(n/j/y g:i:s e)
$text = 'Submission: $current \n
Name: $name \n
Tags: $tags \n
Date: $date \n
Email: $email \n
Other Emails: $oemail \n';
mail($to,$subject,$text);

Link to comment
Share on other sites

Now try this

contact.php

<table bgcolor="white" border="0" align="left" cellpadding="5" width="570">
<tr bgcolor="white">
<td bgcolor="white">
<h3>E-Mail Us</h3>
<br />
<br />
<form name="contact" action="mailer.php" method="post" enctype="multipart/form-data">
Name: <input type="text" name="name" size="25">
<br />
Date Of Event (dd / mm / yy): <input type="text" name="dd" size="2"> <input type="text" name="mm" size="2"> <input type="text" name="yy" size="2">
<br />
Type Of Party: <input type="text" name="type" size="30">
<br />
Phone Number: <input type="text" name="phone" size="12">
<br /> 
E-Mail Address: <input type="text" name="email" size="25">
<br />
Questions: <textarea name="questions" rows="5" cols="60"></textarea>
<br />
<br />
<input name="frm_action1" type="hidden" value="1" />
<input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset" name="reset">
</form>
</td>
</tr>
</table>

 

mailer.php

 

<?php

if(isset($_POST['frm_action1']) && $_POST['frm_action1']==1)
{
$sender = "TMD-Music.com";
$name = $_POST['name'];
$date = $_POST['dd'];
$month = $_POST['mm'];
$year = $_POST['yy'];
$type = $_POST['type'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$text = $_POST['text'];
$today = date("l, F j, Y, g:i a") ;

$body ='This message was auto generated by TMD-Music.com on: {$today}' . "\r\n" .
'Name: {$name}' . "\r\n" .
'Date Of Event: {$date} / {$month} / {$year}"' . "\r\n" .
'Type Of Event: {$type}' . "\r\n" .
'Phone Number: {$phone}' . "\r\n" .
'E-Mail: {$email}' . "\r\n" .
'Message: {$text}';

mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);
}
else
{
echo "Errors Occured....";
}

?>


Your request has been sent. 
<br /> <br />
<a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a>
<br /> <br />

------------------------------------------------------

<?php echo $name ; ?>

Link to comment
Share on other sites

Yes, It is correctly pasted I re copied and pasted both files.

 

And I got the one you sent, and this is what the e-mail contained.

 

TMD-Music.com

 

This message was auto generated by TMD-Music.com on: {$today}

Name: {$name}

Date Of Event: {$date} / {$month} / {$year}"

Type Of Event: {$type}

Phone Number: {$phone}

E-Mail: {$email}

Message: {$text}

 

Link to comment
Share on other sites

Oops.. sorry i didn't notice that

now replace this, hope this works, i will be checking too...

<?php

if(isset($_POST['frm_action1']) && $_POST['frm_action1']==1)
{
$sender = "TMD-Music.com";
$name = $_POST['name'];
$date = $_POST['dd'];
$month = $_POST['mm'];
$year = $_POST['yy'];
$type = $_POST['type'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$text = $_POST['text'];
$today = date("l, F j, Y, g:i a") ;

$body ='This message was auto generated by TMD-Music.com on: {$today}' . "\r\n" .
'Name: "'.$name.'"' . "\r\n" .
'Date Of Event: "'.$date.'" / "'.$month.'"/ "'.$year.'""' . "\r\n" .
'Type Of Event: "'.$type.'"' . "\r\n" .
'Phone Number: "'.$phone.'"' . "\r\n" .
'E-Mail: "'.$email.'"' . "\r\n" .
'Message: "'.$text.'"';

mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);
}
else
{
echo "Errors Occured....";
}

?>


Your request has been sent. 
<br /> <br />
<a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a>
<br /> <br />

------------------------------------------------------

<?php echo $name ; ?>

Link to comment
Share on other sites

Okay, that is sending now, but the date is mssed up.

Also I know that the variable names for message were not matching up earlier, but I have changed that.

 

Here is what is mailed.

 

----------------------------------------------------

 

TMD-Music.com

 

This message was auto generated by TMD-Music.com on: {$today}

Name: "Joe"

Date Of Event: "12" / "18"/ "07""

Type Of Event: "Fun"

Phone Number: "555-5555"

E-Mail: "joe@aol.com"

Message: ""

Link to comment
Share on other sites

Okay this works now. Thanks!!!

 

<?php

if(isset($_POST['frm_action1']) && $_POST['frm_action1']==1)
{

$sender = "TMD-Music.com";
$name = $_POST['name'];
$date = $_POST['dd'];
$month = $_POST['mm'];
$year = $_POST['yy'];
$type = $_POST['type'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$text = $_POST['questions'];
$today = date("l, F j, Y, g:i a") ;

$body ="This message was auto generated by TMD-Music.com on: $today
Name: $name
Date Of Event: $date / $month / $year
Type Of Event: $type
Phone Number: $phone \n
E-Mail: $email \n
Message: $text";

mail("natekrygier@gmail.com","TMD Music Inquiry",$body,$sender);
}
else
{ 
echo "Error." ;
}


?>


Your request has been sent. 
<br /> <br />
<a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a>
<br /> <br />

------------------------------------------------------
<br /> <br />

<?php echo $name ; ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.