Jump to content

[SOLVED] php e-mail form issues


aeafisme23

Recommended Posts

I tried searching the forums and did not find too much that i felt would help me. Here is the code that I got from a website that "works" just like it should but when i add into the form a couple more fields it does not do anything. Also i want to add a BCC if possible if not then i need a CC at the least. Thanks so much for taking a look!

 

works:

<?php

$Subject = "test email";
$toEmail = "[email protected]";

if($submit)
{
mail($fromEmail, $Subject, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">");
}
?>

<html>
<head>
<title>Mail Tutorial</title>
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="<?php echo($PHP_SELF) ?>">
Your E-mail:

<input type="text" name="fromEmail" size="25"> <br>

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

Your Message: <br>

<textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br>

<input type="submit" value="Submit">
<?php 
if(submit)
{
$resultMail = mail($toEmail, $Subject, $nMessage);
if($resultMail)
{
print "Your e-mail has been sent.";
}
else
{
print "Your e-mail has not been sent.";
}
}
?>

 

 

does not work:

<?php
$Subject = "test email";
$toEmail = "[email protected]";

if($submit)
{
mail($fromEmail, $Subject, $fromPhone, $fromAddress, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">");
}
?>
<form method="post" action="<?php echo($PHP_SELF) ?>">
<center><table width=\"700\" cellpadding=\"0\" cellspacing=\"0\">
	<tbody>
	<tr>
		<td><p class="bodyfont">Name*:</p></td>
		<td><input type="text" name="fromName" size="20" /></td>
		<td><p class="bodyfont">Phone:</p></td>
		<td><input type="text" name="fromPhone" size="25" /></td>
	</tr>
	<tr>
		<td><p class="bodyfont">Email*:</p></td>
		<td><input type="text" name="fromEmail" size="20" /></td>
		<td><p class="bodyfont">Address:</p></td>
		<td><input type="text" name="fromAddress" size="30" /></td>
	</tr>
	<tr>
			<td colspan="4"><br><p class="bodyfont">Message*:</p></td>
	</tr>
	<tr>
		<td colspan="4"><p class="bodyfont"><textarea rows="8" name="nMessage" cols="60" class="input"></textarea></p></td>
	</tr>
	<tr>
		<td colspan="4" class="right1"><center><input type="submit" value="Submit" /><input type="reset" value="Reset" /></center><br>
		<p class="bodyfont">*Required Fields Include (Name, Email, and Message)</p></td>
	</tr>
	</tbody>
</table></center>
</form>

 

Link to comment
https://forums.phpfreaks.com/topic/85027-solved-php-e-mail-form-issues/
Share on other sites

//use this conditional
if(submit)


//rather than this one
if($submit)

 

 

It looks like you cut the bottom portion of the sample code off, which was the one doing the work - the top was for testing or something? Anyway, there isn't a variable "$submit" being set anywhere (judging from this code) - but "submit"  is... i think... -u can also use this conditional to test also:  "if(isset($_POST['submit']))"

 

 

another problem could be that your form submit button should have "name=submit" also - that allows you to test if "$_POST('submit')" is set (using "isset")

Have a look at this function:

 

mail($fromEmail, $Subject, $fromPhone, $fromAddress, $nMessage."\nFrom: ".$fromName."<".$fromEmail.">");

 

I don't think you have it correct.

 

it should be:

 

mail($to, $subject, $message, $headers);

 

headers would include things such as:

- to

- from

- cc

- Reply-To

- etc.

You may also want to do this:

 

Change:

<input type="submit" value="Submit">

 

To:

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

 

and do this:

<?php
if(isset($_POST['submit']))
{
if(mail($to, $subject, $message, $headers))
     echo 'Message Sent';
else
     echo 'Message Failed to send';
}
?>

yes, the should look like so:

 

<?php
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";
?>

Ok so i ended up following alot of php.net manual and alot of your advice and i would like to repost code, i am getting a few bugs such as the to address is not sending but the bcc is, the subject is not sending either, and i cant post the message even when i declare the names as variables in the form (just posted 1 as an example) (in the email it just says it like the code looks  and shows the dollar sign $ followed by fromName .... $fromAddress etc..). Any help would be greatly appreciated!

 

CODE:

<?php
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$to = '[email protected]';
$Subject = 'Test: Remind me what again?';

$headers .= 'To: Randy A <[email protected]>, Randy B <rbasdfafxdon.org>' . "\r\n";
$headers .= 'From: The Reminder <[email protected]>' . "\r\n";
//$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

$message = 'You received a message from $fromName their information is $fromPhone, $fromEmail, $fromAddress, and $nMessage';

?>

<form method="post" action="<?php echo($PHP_SELF) ?>">
<center><table width=\"700\" cellpadding=\"0\" cellspacing=\"0\">
	<tbody>
	<tr>
		<td><p class="bodyfont">Name*:</p></td>
		<td><input type="text" name="<?php echo $fromName; ?>" size="20" /></td>
		<td><p class="bodyfont">Phone:</p></td>
		<td><input type="text" name="fromPhone" size="25" /></td>
	</tr>
	<tr>
		<td><p class="bodyfont">Email*:</p></td>
		<td><input type="text" name="fromEmail" size="20" /></td>
		<td><p class="bodyfont">Address:</p></td>
		<td><input type="text" name="fromAddress" size="30" /></td>
	</tr>
	<tr>
			<td colspan="4"><br><p class="bodyfont">Message*:</p></td>
	</tr>
	<tr>
		<td colspan="4"><p class="bodyfont"><textarea rows="8" name="Message" cols="60" class="input"></textarea></p></td>
	</tr>
	<tr>
		<td colspan="4" class="right1"><center><input type="submit" name="submit" value="Submit"><input type="reset" value="Reset" /></center><br>
		<p class="bodyfont">*Required Fields Include (Name, Email, and Message)</p></td>
	</tr>
	</tbody>
</table></center>
</form>

<?php 
if(isset($_POST['submit']))
{
if(mail($to, $subject, $message, $headers))
     echo 'Message Sent Successfully';
else
     echo 'Message Failed to send, please try again later';
}
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.