Jump to content

Php Mail Help


driz
 Share

Recommended Posts

Hi, I've coded this contact form, but it doesn't send the email, and doesn't show the message it worked or didn't work after submitting the form.

	<?php				if(isset($_POST['submit'])) {				$to = $_POST['dept'];				$subject = "";				$name = $_POST['name'];				$company = $_POST['company'];				$tel = $_POST['tel'];				$email = $_POST['email'];				$body = "From: $name\n Company: $company\n Tel: $tel\n E-Mail: $email\n Message:\n $message";				echo "Thanks $name, your email has been submitted to: $to!";				mail($to, $subject, $body);				} else {				echo "Their was an error sending your email.";				}				?>				<form method="post" action="http://solidcamuk.com/contact/index.php">										<div class="span-8">						<p>							<label for="dept">To</label>							<select name="dept">								<option value="" disabled="disabled" selected="selected">Please choose one...</option>								<option value="talk2driz@gmail.com">Support</option>								<option value="talk2driz@gmail.com">Sales</option>								<option value="talk2driz@gmail.com">Other</option>							</select>						</p>						<p>							<label for="name">Name</label><br />							<input type="text" id="name" name="name" value="" maxlength="100" class="title" />						</p>						<p>							<label for="company">Company</label><br />							<input type="text" id="company" name="company" value="" maxlength="100" class="text" />						</p>						<p>							<label for="tel">Telephone</label><br />							<input type="text" id="tel" name="tel" value="" maxlength="100" class="text" />						</p>						<p>							<label for="email">Email address</label><br />							<input type="text" id="email" name="email" value="" maxlength="100" class="text" />						</p>											</div>										<div class="span-8 last">												<p>							<label for="message">Message</label><br />							<textarea id="message" name="message"></textarea>						</p>						<p>							<label></label>							<input type="submit" value="Send" name="submit" />						</p>											</div>								</form>

Any ideas?

Link to comment
Share on other sites

one error i see is that you never set $messagealso,

if(isset($_POST['submit'])) {...} else {  echo "Their was an error sending your email.";}

doesn't make any sense, it tells them there is an error sending if they don't push the submit button?and when i tested it, it appeared to work from my side, it told me "Thanks sdf, your email has been submitted to: talk2driz@gmail.com!" but I obviously don't know if you received the email... but again if you did the message would not be included because it was never set ($message = $_POST['message'];)also... you might want to leave out the "to: talk2driz@gmail.com".... or change it to say "to: Sales" or whatever.... and maybe don't even have the emails in the option values themselves.. but rather have the php change "Sales" to the email internally (so that people/bots can't see your email address. Edited by smerny
Link to comment
Share on other sites

It could be that your web space provider doesn't support the mailto() function. Especially if it's a free web provider. This is because some people can send massive 3gig emails and it eats up the server I'm guessing. This happened to me once.

Edited by MrFish
Link to comment
Share on other sites

Okies turns out IT WAS WORKING! The emails were ending up in the Spam. Also I have now set the $message but the textarea content was STILL getting sent, not sure how that was working? But either way I've added it just to be safe.The problem now is the From, the email is coming into my inbox as being From the root server admin, what I want it be is from the person who sent the email, how can I change the code to do this? Thanks.

Link to comment
Share on other sites

You need to set a valid From header, e.g.

mail($to, $subject, $body, "From: $name <email@your-domain.com>\r\n");

Link to comment
Share on other sites

It's hard to figure out why some email systems mark some emails as spam. They might be using SPF to verify the server, or they might do a DNS lookup to figure out if the server where the email originated is the mail server for that domain, or maybe it just doesn't like the content of the message. Which email system is marking it as spam?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...