Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form to mail problem

Status
Not open for further replies.

GavW

Programmer
Jan 13, 2006
58
GB
Hey all!

I am having problems with my form to email script. Ive looked at numerous tutorials and i am prety sure that i am not coding anything wrong.

I am simply using two pages:

contact.php - includes the form which submits to...
sendmail.php - uses the php mail function (mail($to,$subject.....))

could it be possible that the server which i am hosting my site on will not accept posting to an outside email address? i have read this somewhere. is there any way to overcome this?

Thanks in advance.

GavW
 
Unfortunately, there is still insufficient data for a meaningful answer.

What does sendemail.php, the script to which the form submits data, look like?



Want the best answers? Ask the best questions! TANSTAAFL!
 
The code inside of the body tags looks like this:

<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
echo $badinput;

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("test316@gmail.com", $subject, $message, $from);

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="contact.php"> Next Page </a>
</p>
 
Let's see....

First, don't post code with e-mail addresses in it. This site is readable by the entire internet.


This construct:

!$visitormail == ""

is interesting. Since negation (the "!" operator) has higher precedence than comparison (the "==" operator), that expression may not be what you think it is. Instead, use:

$visitormail != ""


Have you tried sending a simple test e-mail using mail() in a simpler script? It could be that your mail configuration is not right.


Have you verified that all the variables used to pass values to mail() have what you expect?





Want the best answers? Ask the best questions! TANSTAAFL!
 
not sure what you mean. I have been unable to send any email using this script although looking at a lot of internet tutorials this appears to be the way in which it is done.
 
can you try simply the following:

Code:
<?
$to = "" ;// your email address
$subject = "Subject goes here";
$body = "Body goes here\r\n";
mail($to, $subject, $body, "From: {$to}\r\n") or die("Cannot send mail");
?>

this will tell us whether you can send mail at all with your configuration. Once we establish whether your setup is right we can start looking at the code.
 
the script itself runs fine no error is returned. I am just not receiving an email at my address. I have tried it with both my gmail and hotmail accounts and none are receiving it.
 
check your spam filters.

i invariably find that automated email from my own servers and in my own domains end up in spam filters.

btw the fact that no error is returned is not proof at all that the mail is sent - only that there has been no problem with php. it is then up either to your smtp server (if you are using windows) or sendmail ([or other MTA] if you are using linux) actually to send the mail.

when you post back - if things are not working - please include a description of what platform you are using (linux/windows) and the relevant bits from phpinfo() about sendmail and/or smtp (again depending whether you are using linux/windows)
 
Do you have the capability to examine the logs of your mail server? Perhaps that will give a clue as to what is stopping the delivery.

Have you tried using PHPMailer ( )? Sometimes it will automagically add headers to messages that will allow their delivery.

But GavW, have you explicitly tried the simplest possible test script to send email? Something like:

<?php
mail ('<your email address here>', 'test message', 'test message');
?>

?



Want the best answers? Ask the best questions! TANSTAAFL!
 
just tried that simple script.....no luck.

do you know if ASP uses the same emailing method as PHP as i have an ASP support page script that works wonders:


If all fails i might attempt to use this script for my PHP site although I hear its not too wise to cross languages.
 
could this be the problem maybe? My php.ini file:

[mail function]
; For Win32 only.
SMTP = localhost ; for Win32 only
smtp_port = 25
sendmail_from= gavw316@gmail.com ; for Win32 only

; For Win32 only.
;sendmail_from = me@example.com
 
the link that you provided above (test.php) pulls up inter alia the contents of your php.ini file. this indicates that the mail settings that you are using are:

sendmail_from me@localhost.com
SMTP 213.171.216.21
smtp_port 25

thus the php.ini file you refer to in your last post is not getting parsed by the server.

do you want to use localhost as your smtp server? the IP address given by your current setup (with fasthosts by the look of it) is a valid smtp server. i cannot tell (obviously) whether you have the right permissions to use this.

have you logged a trouble ticket with fasthosts? there is some evidence on the web that php mail has stopped working for other users on fasthosts.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top