Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

php email problem

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=369030:date=Apr 26 2006, 10:59 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 26 2006, 10:59 PM) [snapback]369030[/snapback][/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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[code]
<!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>

[/code]
form above
processor below
I finally got those arrays to work right.
[code]
<!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>

[/code]

[b]Some of these had dirty languages so I edited them.[/b]

Share this post


Link to post
Share on other sites
The reason why your emails are being sent twice is becuase you are using mail twice:
[code]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";
}
?>[/code]
You dont need it twice only one. so remove the first instance of the mail function from your script.

Share this post


Link to post
Share on other sites
[!--quoteo(post=369560:date=Apr 28 2006, 08:40 AM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 28 2006, 08:40 AM) [snapback]369560[/snapback][/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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.