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!
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$email = ($_POST['userEmail']);
$to = $email;
$subject = 'Registration Confirmation';
$body = 'Hello'. $first . ', Thank you for registering with Capital Abode.';
$headers = 'From: noreply@capitalabode.com' . "\r\n";
mail($to, $subject, $body, $headers);
}
?>
The mail() function still doesn't work, so I'm guessing that the form isn't being submitted. How is that possible when the user's details are being entered into the database? Surely that's a clear sign of form submission...?
<?php
$to='your@email.com';
$subject='testing mail()';
$message='Dude it works!';
//some simple headers, because some servers like reply set - so change the address to one on your domain
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to,$subject,$message,$headers)) echo "Mail works, now check your inbox!";
?>
mail() works perfectly well on my server...I received the email immediately when I typed my email address into the code. It's trying to capture an email address entered in the form which is causing me a great deal of grief
Sometimes emails sent from PHP take a long time to arrive - which is irritating when testing!
Not sure what you are asking now? The var_dump checked that the userEmail was being set in the form which it is. You can remove that now. The fact you got the email means its working, doesn't it?
If it is, you now need to make it safe. If you put user input in the "to" part of a mail call without checking it is just an email address then you are opening the script up to spammers hijacking the form to send millions of email inviting us to enlarge things etc. Search for "email validation" on the forum!
I meant that just THAT piece of code (plus a very simple HTML form) worked...I received an email. But when I put that piece of code back into my original code...I get nothing
I guess I'll have to debug...but if you find anything that could be acting as a hindrance to the mail() function in my original code, then I would greatly appreciate it as I have spent FAR too long on this...more than I intended
Basically, the form action is set to a file called process.php, which is incredibly important to run as it contains the database queries in order to allow a user to register. However, after testing out the mail() function several times on its own and with the form, it appears that the problem lies in the form action. I cannot process the form and therefore get the registration form to send an email to a new user unless I set the form action to
which is something that I REALLY don't want to as it has taken me FOREVER to get the registration and login to work.
If I do set it to this, then I won't be able to register a new user. Is there a way around this or am I officially stuck?
It sounds like you are expecting form POST data to persist through more than one form.
What I mean is are you posting the $_POST['userEmail'] to the registration script and then the user submits another form, the result of which is that the userEmail has disappeared?
No, it's all one form. The user enters their details into the registration form and the details are entered into the database from there, while an email is sent as soon as the form has been submitted.