Jump to content

Mail Form Help


kross
Go to solution Solved by fastsol,

Recommended Posts

Hello everyone.. I know next to nothing about PHP but I'm trying to set up a mail form on a html web page. The code I've used should work, but for some reason the email wont send. When I hit send, the message pops up saying that it sent, but it doesnt send. What am I missing or doing wrong?

 

Here's the code

<?php
                            function spamcheck($field)
                              {
                              //filter_var() sanitizes the e-mail
                              //address using FILTER_SANITIZE_EMAIL
                              $field=filter_var($field, FILTER_SANITIZE_EMAIL);

                              //filter_var() validates the e-mail
                              //address using FILTER_VALIDATE_EMAIL
                              if(filter_var($field, FILTER_VALIDATE_EMAIL))
                                {
                                return TRUE;
                                }
                              else
                                {
                                return FALSE;
                                }
                              }
                                if (isset($_REQUEST['email']))
                                {//if "email" is filled out, proceed
                                
                                  //check if the email address is invalid
                                    $mailcheck = spamcheck($_REQUEST['email']);
                                    if ($mailcheck==FALSE)
                                    {
                                    echo "Invalid input";
                                    }
                                  else
                                  {
                                  //send email
                                  $name = $_REQUEST['name'] ;
                                  $email = $_REQUEST['email'] ;
                                  $subject = $_REQUEST['subject'] ;
                                  $message = $_REQUEST['message'] ;
                                  mail("someone@something.com", "Subject: $subject",
                                  $message, "From: $email" );
                                  echo "Sent. Thank you!";
                                  }
                                  }
                                else
                                //if "email" is not filled out, display the form
                                  {
                                  echo "<form method='post' action='contact.php'>
                                  What's your name?
                                    <br />
                                    <input name='name' type='text' required />
                                    <br />
                                  What's your Email address?
                                    <br />
                                <input name='email' type='text' required>
                                <br />
                                  What is the matter regarding?
                                    <br />  
                                <input name='subject' type='text' required>
                                    <br />
                                  What is your message?
                                  <br />
                                  <textarea name='message' rows='15' cols='50' required></textarea>
                                  <br />
                                  <br />
                                  <input type='submit' value='Send'>
                                  </form>";
                                  }
                            ?>

Keep in mind that the someone@something.com is not the email I tried sending it to. I've tried multiple email accounts I have on yahoo and gmail with no luck. And yes, the file is saved in a folder on a server that has php installed.

 

Thank you for your time!!!

Link to comment
Share on other sites

Have you switched hosts recently? Try the below code on your server:

<?php
if(mail("someone@example.com", "Subject: $subject", $message, "From: $email"))
{
echo "Email Sent.";
} else {
echo "Email NOT Sent.";
}
?>
Link to comment
Share on other sites

I'm sorry, but was I supposed to plug that into my existing code or run that by itself essentially? I plugged it into mine and I think I'm getting a syntax error because the page is completely blank when I load it. This is what I did

<?php
							function spamcheck($field)
							  {
							  //filter_var() sanitizes the e-mail
							  //address using FILTER_SANITIZE_EMAIL
							  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

							  //filter_var() validates the e-mail
							  //address using FILTER_VALIDATE_EMAIL
							  if(filter_var($field, FILTER_VALIDATE_EMAIL))
								{
								return TRUE;
								}
							  else
								{
								return FALSE;
								}
							  }
								if(isset($_REQUEST['email']))
								{//if "email" is filled out, proceed
								
								  //check if the email address is invalid
									$mailcheck = spamcheck($_REQUEST['email']);
									if ($mailcheck==FALSE)
									{
									echo "Invalid input";
									}
								  else
								  {
								  //send email
								  $name = $_REQUEST['name'] ;
								  $email = $_REQUEST['email'] ;
								  $subject = $_REQUEST['subject'] ;
								  $message = $_REQUEST['message'] ;
								  if(mail("someone@example.com", "Subject: $subject",
								  $message, "From: $email" ))
								  {
								  echo "Message sent. Thank you!";
								  } else {
								  echo "Message Not sent. Sorry.";
								  }
								else
								//if "email" is not filled out, display the form
								  {
								  echo "<form method='post' action='contact.php'>
								  What's your name?
									<br />
									<input name='name' type='text' required />
									<br />
								  What's your Email address?
									<br />
								<input name='email' type='text' required>
								<br />
								  What is the matter regarding?
									<br />  
								<input name='subject' type='text' required>
									<br />
								  What is your message?
								  <br />
								  <textarea name='message' rows='10' cols='25' required></textarea>
								  <br />
								  <br />
								  <input type='submit' value='Send'>
								  </form>";
								  }
							?>
Link to comment
Share on other sites

It returned "Email Sent" but I didnt recieve an email. I even waited a few minutes

 

 

I checked spelling, resent, and tried different addresses, but still wont work

Edited by kross
Link to comment
Share on other sites

  • Solution

The script test that Coreye gave was the most common way to test a mail().  If the mail never arrives it would indicate only a couple things.  One, even though mail() is available on your server doesn't mean they have a mail service setup, to know that you would need to ask them or see if they have sample code of how to send mail on their servers.  Two, their mail service is being over strict and marking any of your attempts as spam.  Have you checked your spam forlder by chance to make sure they didn't arrive there instead?

 

If they are in you spam folder by accident, you may really want to consider using the phpmailer library from http://phpmailer.worxware.com/ cause they have all the mail headers setup correctly and many other features you can do easily.  That will help ensure "better" that your mail arrives in the inbox and not spam folders.

Link to comment
Share on other sites

I figured it out...

 

 

Using PuTTy, I logged into my server and a message popped up saying that new "security" feature was added to the servers and that email can only be sent to addresses provided by school. :( no personal email addresses are allowed anymore.

 

Thanks for your help guys!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.