Jump to content


Photo

php email problem


  • Please log in to reply
7 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 April 2006 - 09:59 PM

I have learnt alot, I now know there is not just one set way to do everything, so I have been fighting with code trying to figure out ways to do things on my own, and things are coming together, I am having one problem here. I have a difficulty with any email script I create that gatheres form information, whenever I submit the form it emails it to me twice. Actually I ahve 2 questions.
1. Why does it email itself to me twice for each time I hit submit, is it somethign wrong with my script, or is there anyway to stop that. I know anything is possible with php but this is somethign I Don't know how to start with, I just began.
2. Why does it come into junk mail, at first it was, I set it to not junk in hotmail, and it worked, but if I ever send an email through php it is going to send it to junk mail, is there a way to change this at all, it will make it hard if I am every setting up email systems for people, or setting up something for, mailing lists, that is going to cause one major problem.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 DepretioN

DepretioN
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 26 April 2006 - 10:04 PM

[!--quoteo(post=369030:date=Apr 26 2006, 10:59 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 26 2006, 10:59 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I have learnt alot, I now know there is not just one set way to do everything, so I have been fighting with code trying to figure out ways to do things on my own, and things are coming together, I am having one problem here. I have a difficulty with any email script I create that gatheres form information, whenever I submit the form it emails it to me twice. Actually I ahve 2 questions.
1. Why does it email itself to me twice for each time I hit submit, is it somethign wrong with my script, or is there anyway to stop that. I know anything is possible with php but this is somethign I Don't know how to start with, I just began.
2. Why does it come into junk mail, at first it was, I set it to not junk in hotmail, and it worked, but if I ever send an email through php it is going to send it to junk mail, is there a way to change this at all, it will make it hard if I am every setting up email systems for people, or setting up something for, mailing lists, that is going to cause one major problem.
[/quote]

Is it an HTML E-mail? Hotmail sends most of those to Junk Mail.

What happens when you hit submit? Does the script reload itself?

#3 koencalliauw

koencalliauw
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 26 April 2006 - 10:08 PM

Hi,

as for the problem with sending your email twice, please give us the full email code.
I had similar problems with this, but my problem was kinda funny, I had a button that was <input type='image' onclick='javascript:document.forms[0].submit();' src='someimage.jpg' />, this created the problem:

first send: the image type is the same as the submit type, so the form gets submitted
second send: the javascript sends the form, so the mail gets sent a second time

as for the junk mail problem, make sure all mail headers are set correctly (especially the from email address/name, maybe reply-to if you need it.

Koen.

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 27 April 2006 - 09:36 PM

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>php test page</title>
</head>
<body>
Please fill in the following form and submit the information to me:<br  />
<form name="formtest" action="formprocessor.php" method="post">
First Name:<input name="firstname" type="text" maxlength="30" /><br />
Last Name:<input name="lastname" type="text" maxlength="30" /><br />
Age:<input name="age" type="text" maxlength="3" /><br />
Please enter desired Username:<input name="username" type="text" maxlength="35" /><br />
Please verify Username:<input name="verifyusername" type="text" maxlength="35" /><br />
Please enter desired password:<input name="password" type="password" maxlength="25" /><br />
Please verify your password:<input name="verifypassword" type="password" maxlength="25" /><br />
Now for the section to tell me a little bit about yourself.<br />
Please enter information about your personal life below:<br />
<input name="personallife" type="text" /><br />
Please enter all the programming languages you currently know:<br />
<input name="languages" type="text" /><br />
Please enter all your past experiences below:<br />
<input name="experiences" type="text" /><br />
Please check all that apply:<br />
I am:<br />
Perfect:<input name="iam[]" type="checkbox" value="perfect" /><br />
Obedient:<input name="iam[]" type="checkbox" value="obedient" /><br />
Incoherent:<input name="iam[]" type="checkbox" value="incoherent" /><br />
Drunk:<input name="iam[]" type="checkbox" value="drunk" /><br />
Unfocused:<input name="iam[]" type="checkbox" value="unfocused" /><br />
Desired:<input name="iam[]" type="checkbox" value="unfocused" /><br />
Unrelenting:<input name="iam[]" type="checkbox" value="unrelenting" /><br />
Full of crap:<input name="iam[]" type="checkbox" value="fullofcrap" /><br />
Uncircumsized:<input name="iam[]" type="checkbox" value="uncircumsized" /><br />
How would you say the following please pick only one:<br />
Thank you:<input name="choice" type="radio" checked="checked" value="thankyou" /><br />
Go To heck:<input name="choice" type="radio" value="gotoheck" /><br />
What are you doing:<input name="choice" type="radio" value="whatareyoudoing" /><br />
Now please pick out of the following, which ones apply to you:<br />
Fat:<input name="decision[]" type="checkbox" value="fat" /><br />
Skinny:<input name="decision[]" type="checkbox" value="skinny" /><br />
Tall:<input name="decision[]" type="checkbox" value="tall" /><br />
Short:<input name="decision[]" type="checkbox" value="short" /><br />
Man:<input name="decision[]" type="checkbox" value="man" /><br />
Woman:<input name="decision[]" type="checkbox" value="woman" /><br />
<input name="submit" type="submit" value="submit me now" />
<input name="reset" type="reset" value="reset this and die" />
</form>

</body>
</html>

form above
processor below
I finally got those arrays to work right.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form processor</title>
</head>
<body>
<?php
$to = "businessman332211@hotmail.com";
$subject = "Freelance businessman test";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$username = $_POST['username'];
$verifyusername = $_POST['verifyusername'];
$password = $_POST['password'];
$verifypassword = $_POST['verifypassword'];
$personallife = $_POST['personallife'];
$languages = $_POST['languages'];
$experiences = $_POST['experiences'];
$choice = $_POST['choice'];
$message = "
First Name: $firstname
Last Name: $lastname
Age: $age
User Name: $username
Verify Username:$verifyusername
Password: $password
verifypassword: $verifypassword
Personal Life: $personallife
Languages: $languages
Experiences: $experiences
choice: $choice
I Am: ";
$message .= implode(', ', $_POST['iam']) . "\n" . 'Decision: ';
$message .= implode(', ', $_POST['decision']);

mail($to, $subject, $message);

if (mail($to, $subject, $message)){
print "The email has been sent";
} else {
print "The email has not been sent";
}
?>

</body>
</html>


Some of these had dirty languages so I edited them.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 April 2006 - 08:46 AM

The reason why your emails are being sent twice is becuase you are using mail twice:
mail($to, $subject, $message); //remove this line

if (mail($to, $subject, $message)){
print "The email has been sent";
} else {
print "The email has not been sent";
}
?>
You dont need it twice only one. so remove the first instance of the mail function from your script.

#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 April 2006 - 12:40 PM

don't I need it once for it to send, and once to test it to see if it sent??

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 April 2006 - 12:46 PM

[!--quoteo(post=369560:date=Apr 28 2006, 08:40 AM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 28 2006, 08:40 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
don't I need it once for it to send, and once to test it to see if it sent??
[/quote]
No. Just follow wildteen88's advice.

Legend has it that reading the manual never killed anyone.
My site

#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 April 2006 - 01:37 PM

thanks

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users