PDA

View Full Version : mail() Not sending.



heyden
February 23rd, 2007, 11:09 PM
I'm having a little trouble with my contact form. The vars are working properly and everything, only problem is the mail() won't mail. It works for my wordpress install and another script I use, so I'm not sure why it is not working here.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Atlantor - Redefining the way you RP</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="generator" content="Atlantor - DEV" />
<style type="text/css" media="all">@import "/css/global.css";</style>
</head>

<body>

<?

if($_POST) {

$to = "w1se17@gmail.com";
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['comments'];

if(mail($to, $subject, $message)) {
echo "Mail sent.<br />";
echo "<a href=\"index.php\" title=\"Dev Homepage\">Back to dev</a>";
echo "<br />" . $to . "<br />" . $from . "<br />" . $subject . "<br />" . $message;
} else {
echo "Mail could not be sent. <br />";
echo "<a href=\"index.php\" title=\"Dev Homepage\">Back to dev</a>";
}
} else {
?>
<h1>Contact</h1>
If you'd like to leave some feedback, or report problems/bugs, please fill out this form and submit it. We will get back
to you as soon as we can.

<form method="post" action="contact.php">

<table width="400">
<tr><td width="100"> Your E-Mail:</td> <td><input type="text" name="email" size="60" /></td></tr>
<tr><td>Subject:</td> <td><input type="text" name="subject" size="60" /></td></tr>
<tr><td valign="top">Comments:</td> <td><textarea name="comments" rows="10" cols="30"></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="submit" /></td></tr>
</table>

</form>

<?
}
?>

</body>
</html>
I've tried many params for mail(). Any help is appreciated :). Thanks in advance. I'm going to add more security once I figure out why mail() isn't mailing, so it's pretty basic right now.

Man Hsu
February 24th, 2007, 03:23 AM
Sounds like a mail server problem.
"For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file."

evildrummer
February 24th, 2007, 05:04 AM
Safe a .php file called info.php, and in that have:


phpinfo();

then upload it and open it in your browser and look for the main section, you can then check its all set-up right.




also just a note it would be faster if you did this:


<?php

if($_POST) {

$to = 'w1se17@gmail.com';
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['comments'];

if(mail($to, $subject, $message)) {
echo 'Mail sent.<br />';
echo '<a href="index.php" title="Dev Homepage">Back to dev</a>';
echo '<br />'.$to.'<br />'.$from.'<br />'.$subject.'<br />'.$message;
} else {
echo 'Mail could not be sent. <br />';
echo '<a href="index.php" title="Dev Homepage">Back to dev</a>';
}
} else {
?>
In case you didnt notice I swapped all " for ', this has several benefits, firstly, you dont have to use ugly escape characters in the html, and also it is faster, for more info, theres a good explanation here: http://brianhaveri.com/?id=34

heyden
February 24th, 2007, 09:11 PM
If someone wants to check...

http://dev.atlantor.net/phpinfo.php

Lmk if mail() should be working...I'm not sure where to look :(.

evildrummer
February 25th, 2007, 07:23 AM
instead of checking the if($_POST) have hidden value form and have that checked, I think that would make it work!