Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

John J Rambo

macrumors member
Original poster
Mar 10, 2010
37
0
Belfast
Hi guys,

Im completely new to php and I'm trying link a php script to this form I have:

PHP:
<form action="contactformprocess.php" method="post">
		<fieldset>
			<label for="name">Name:</label>
			<input type="text" name="name" placeholder="Enter your full name" />

			<label for="email">Email:</label>
			<input type="email" name="email" placeholder="Enter your email address" />

			<label for="message">Message:</label>
			<textarea name="message" placeholder="What's on your mind?"></textarea>

			<input type="submit" value="Send message"  name="submit"/>

		</fieldset>
	</form>

I cant see anything wrong with this form and i have linked a php mailer script to it but I'm not receiving the email...

I'm testing it live by the way.

thank in advance...
 
Last edited by a moderator:
It's probably your email script...

When you have a php form using POST variables like you do (method="post") and your not sure about the form part all you need to do is to put this test code in the page your submitting to in this case contactformprocess.php.

PHP:
<pre>
<?php
print_r($_POST);
?> 
</pre>

<?php exit; ?>

This will print out the POST array showing you all the values that were submitted. That way you know that the form submission is good if you get the expected results and you can then debug the submit to script.

Usually I put in a exit or die statement after the closing </pre> tag to stop the script execution so I can easily see the POST array contents. The <pre> tags aren't needed but they format the array so it's easy to read.
 
Last edited:
Hi, thanks for the responses guys. Below is my php script:

PHP:
<?php

/* subject and eamil variables */


	$emailSubject = 'hello!';
	$webMaster = 'info@avenue19ni.com';
	

/* Gathering Data Variables */

	$name = $_POST['name'];
	$email = $_POST['email'];
	$message = $_POST['message'];
	
	$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Message: $message <br>
EOD;

	$headers = "From: $email\r\n";
	$headers .= "Content-type: text/html\r\n";
	$success = mail($webMaster, $emailSubject, $body, $headers);
	
/* Results rendered as HTML */

	$theResults = <<<EOD
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="screen" /> 
<title>Contact Form Complete</title>
</head>

<body>


</body>

</html>
EOD;
echo "$theResults";

?>

thanks again, this is driving me crazy...
 
Last edited by a moderator:
I only had a few minutes this morning to look at this but I believe the main problem is your not calling the "mail" command. You have this line but it's not doing anything as it's just a variable...

PHP:
$success = mail($webMaster, $emailSubject, $body, $headers);

If you just use this it should work...

PHP:
mail($webMaster, $emailSubject, $body, $headers);

You may have other things to work out but this should send the email massage and you should be able to retrieve it at info@avenue19ni.com.
 
I only had a few minutes this morning to look at this but I believe the main problem is your not calling the "mail" command. You have this line but it's not doing anything as it's just a variable...

PHP:
$success = mail($webMaster, $emailSubject, $body, $headers);

If you just use this it should work...

PHP:
mail($webMaster, $emailSubject, $body, $headers);

You may have other things to work out but this should send the email massage and you should be able to retrieve it at info@avenue19ni.com.

Hi thanks for looking at this, I tried what you said but Im still not able to receive the email, could there be a server setting or email setting that I need to enable?

thanks
 
Hi thanks for looking at this, I tried what you said but Im still not able to receive the email, could there be a server setting or email setting that I need to enable?

thanks

Worked for me, sent to my gmail email address. I didn't use the form, just hard coded the variables on the email script.
 
Worked for me, sent to my gmail email address. I didn't use the form, just hard coded the variables on the email script.

You're a star! I just tested it with my hotmail address and it works but its not going to my other email which it needs to, any ideas?

Its not even landing in the trash...
 
You're a star! I just tested it with my hotmail address and it works but its not going to my other email which it needs to, any ideas?

Its not even landing in the trash...

Email can be a pain.... your other account could be trashing it, who knows... try to get as simple and basic as you can with your testing. I also use phpmailer you might want to look into that. Good luck.
 
I only had a few minutes this morning to look at this but I believe the main problem is your not calling the "mail" command. You have this line but it's not doing anything as it's just a variable...

PHP:
$success = mail($webMaster, $emailSubject, $body, $headers);

If you just use this it should work...

PHP:
mail($webMaster, $emailSubject, $body, $headers);

You may have other things to work out but this should send the email massage and you should be able to retrieve it at info@avenue19ni.com.

Just saying, this advice is incorrect. The first version was simply capturing the return value from the function. The second is discarding the return value. Both are calling the function.
 
Just saying, this advice is incorrect. The first version was simply capturing the return value from the function. The second is discarding the return value. Both are calling the function.

Sorry to disagree... the script didn't work until the mail function was called directly.. maybe you should try running the code first---
 
Sorry to disagree... the script didn't work until the mail function was called directly.. maybe you should try running the code first---

There's no difference between these two bits of code in "calling it directly". Both syntaxes are directly calling the function. Do you understand how return values work?
 
It wasn't because of that line.

I was finally able to check that and your are CORRECT it wasn't that line - I found that the reason it didn't work was that I had $webmaster and $email set to the same email address and something didn't like that... case closed.
 
I was finally able to check that and your are CORRECT it wasn't that line - I found that the reason it didn't work was that I had $webmaster and $email set to the same email address and something didn't like that... case closed.

Nice! And sorry if I came across as a jerk at any point -- wasn't my intent, honest :)
 
The mail function returns a success or denied variable. Both function calls were fine. I have had issues sending mail to gmail before. I can't remember what I did to fix it. I'm thinking it was something with the headers but it may have been with the server.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.