mail sending problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grissemann
Forum Newbie
Posts: 1
Joined: Fri May 28, 2004 2:03 pm

mail sending problem

Post 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.
Sycor
Forum Newbie
Posts: 8
Joined: Fri Jun 11, 2004 3:54 am

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Sycor wrote:"AND", which should be "&&"
Grumble grumble :)
Post Reply