Page 1 of 1

mail sending problem

Posted: Fri May 28, 2004 2:03 pm
by grissemann
I have posted a short snippet from my mail-sending dialog. normally it is working, and sometimes no error and no email is sent, any suggestions to improve this code, I know it is really ugly, my first php script ...
(i'm a complete php newbie, my special subject is java and .net)

thank u for your help!
gm

Code: Select all

<?
$action = "show";

if (!isset($_SERVER)) { $_POST =& $HTTP_POST_VARS; $_SERVER =& $HTTP_SERVER_VARS; }

if(isset($_POST['submit'])) 
{
	if ($email <> null and $firstname <> null and $lastname <> null and $email <> null)
	{
		$body = "Anfrage von Homepage: \r\n";
		$body .= "Daten:\r\n";

		$from = "$email";
		$to = "xxx@xx.xx";

    	if (mail("$to","subject","$body","From: $from")) 
		{
			$body = "Vielen Dank für Ihre Anfrage! \r\n\r\n";
			$body .= "bla, bla \r\n\r\n";
			
			$from =  "xx@xx.xx";
			$to = "$email";
			
			if (mail("$to","subject confirmation","$body$","From: $from"))
			{
				echo "bla bala";
				$action = "sent";
			}
			else
			{
				echo "Vielen Dank für Ihre Anfrage.";
				$action = "sent";
			}
		} 
		else 
		{
			$action = "sendError";
			echo "Die Email konnte wegen eines technischen Problems nicht gesendet werden!";
		}
	}
	else
		$action = "missing";
}	

?>
thank u for your help!
gm

edit patrikG: PLEASE EVERYONE: learn to use

Code: Select all

-tags around php-code. Thanks.

Posted: Fri Jun 11, 2004 5:53 am
by Sycor
So far, the only problems I have seen are:
"=&", which should be ".="
"<>", which should be "!="
"AND", which should be "&&"

Also, for the line:

Code: Select all

if ($email <> null and $firstname <> null and $lastname <> null and $email <> null)
the different comparisons should be grouped like:

Code: Select all

if (($email != null) && ($firstname != null) && ($lastname != null) && ($email != null))
but you cannot compare the strings to "NULL". Instead you can compare them to "", an empty string, though it is better to use:

Code: Select all

if (!empty($email) && !empty($firstname) && !empty($lastname) && !empty($email))
I hope it helps.

Posted: Fri Jun 11, 2004 6:19 am
by Grim...
Sycor wrote:"AND", which should be "&&"
Grumble grumble :)