Jump to content

mail function problem


Sebolains

Recommended Posts

Hey guys!

First of all, thanks for taking the time to read this.

 

I currently have a website with a contact form in it. The contact form sends me an email with the inputted data. Now, for some reason I seem to be getting this back whenever I try the code out on my apache local server:

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Program Files (x86)\VertrigoServ\www\contact.php on line 49

 

The contact form is not working, and it's always returning "There was a problem sending your feedback, please try again later.". In case you need it, here's the code:

 

<?php

$myemail = '[email protected]';
$subject = 'DCanime General Contact';

$op = $_POST[op];

if($op == 'contact')
{
	$name = stripslashes($_POST[name]);
	$email = stripslashes($_POST[email]);
	$category = stripslashes($_POST[category]);
	$text = stripslashes($_POST[text]);
	$referer = $_POST[referer];
	$remote_host = $_SERVER[REMOTE_ADDR];
	$server = $_SERVER[sERVER_NAME];
	$browser = $_SERVER[HTTP_USER_AGENT];

	if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email)) 
	{ 
		$status = "We're sorry, but you've entered an incorrect email address.";
	}
	if(!$name)
	{
		$status .= "Please enter your name.";
	}
	if(!$text)
	{
		$status .= "Please enter a message.";
	}

	if(!$status)
	{
		$header = "From: $email" . "\r\n";

		$message = "
			Name: $name
			Referer: $referer
			Site: $server
			Remote Host: $remote_host
			Remote Browser: $browser


			Category: $category

			$text
		";

		if(mail($myemail, $subject, $message, $header))
		{
			$status = "Thank you for your Feedback!!";
		}
		else
		{
			$status = "There was a problem sending your feedback, please try again later.";
		}

	}
	else
	{
		$status .= "Please press <u>back</u> on your browser to resubmit.";
	}
}    

$referer = $_SERVER[HTTP_REFERER];

if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer))
{
	unset($referer);
}

?>

<h1>Contact Us</h1>
<form method="post" action="<?php print $_SELF; ?>">
<p class="result"><?php print $status; ?></p>

<input type="hidden" name="op" value="contact">
<input type="hidden" name="referer" value="<?php print $referer; ?>">

<p>
	<label>Name:</label>
	<input class="text" type="text" name="name">
</p>
<p>
	<label>Email address:</label>
	<input class="text" type="text" name="email">
</p>
<p>
	<label>Category:</label>
	<select name="category">
		<option value="general">General Inquires</option>
		<option value="problem">Report a Problem</option>
		<option value="team">Team Application</option>
		<option value="other">Other</option>
	</select>
</p>
<p>
	<label>Message:</label>
	<textarea name="text"></textarea>
</p>
<input type="submit" class="submit" value="Send!" />
</form>

 

Do you guys know what the problem is? Is the code the problem or should I change something else? It's not working either when I try uploading it to my host, although I don't get the php.ini message when I try it out there.

 

I appreciate your help,

 

Seb.

Link to comment
https://forums.phpfreaks.com/topic/201316-mail-function-problem/
Share on other sites

get rid of the form, and just make a test.php file with this inside.

 

<?php

mail('[email protected]', 'Test Subject', 'Test Message');

?>

 

If when you installed apache you did not configure the smtp settings, it will not work when testing on localhost.

 

As for your host not working.... well that would be something on their end, upload the above script and see if you get errors.

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.