stjonesMSI Posted May 18, 2015 Share Posted May 18, 2015 Hello.I do the website for my employer and and have been asked to get our job application online. I have created the form at http://www.morgansmithllc.com/job_app.html. I have set the form to -- action="send_job_app.php" method="post"To test things out, the PHP file is trying to just email me the applicant name and address. The PHP code is (located at http://www.morgansmithllc.com/send_job_app.php):<?phpini_set('display_startup_errors',1);ini_set('display_errors',1);error_reporting(-1); $name = $_REQUEST['applicant_name'] ; $address = $_REQUEST['applicant_address'] ; mail( "deleted_for_public_posting_purposes", "Online Job Application", $address, "From: $name" ); header( "Location: http://www.morgansmithllc.com/job_app_thanks.html" ); ?>When I SUBMIT, I get no errors - but no email ever arrives. To compound the problem of troubleshooting, I don't have access to the mail servers. I have to rely on our IT person for issues there. My starting question is, is the any reason that what I've done wouldn't work based on my coding?Thanks!Steve Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/ Share on other sites More sharing options...
Barand Posted May 18, 2015 Share Posted May 18, 2015 For a start, unless your email address is "deleted_for_public_posting_purposes" then it's going nowhere. I suggest you look up mail in the manual paying attention to the required arguments and structure of headers. Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512136 Share on other sites More sharing options...
ginerjm Posted May 18, 2015 Share Posted May 18, 2015 You should study the manual where it describes the syntax of the mail() function. Your header parm is not correct, unless your 'applicant_name' form field is inappropriately named. Going further than I have ever before, here is what you need to send: to address (of course and you have done so) subject (you got it) message body (you have the contents of 'applicant address' here) headers - usually the from address (you have the applicant name here) Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512137 Share on other sites More sharing options...
stjonesMSI Posted May 18, 2015 Author Share Posted May 18, 2015 For a start, unless your email address is "deleted_for_public_posting_purposes" then it's going nowhere. I suggest you look up mail in the manual paying attention to the required arguments and structure of headers. No - that obviously isn't an email address. It has been "redacted" so my real work email address is not posted in an online public forum to avoid getting spam. There is a legitinate email address in the actual code. Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512139 Share on other sites More sharing options...
stjonesMSI Posted May 18, 2015 Author Share Posted May 18, 2015 (edited) Ok - both responses (which I appreciate) have refered to "the manual". I have no idea what manual you refer to or where it is located. I am BRAND NEW to PHP and have been looking at examples on the web to start with. Where is this "manual" located? Thanks. Edited May 18, 2015 by stjonesMSI Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512141 Share on other sites More sharing options...
CroNiX Posted May 18, 2015 Share Posted May 18, 2015 php.net Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512142 Share on other sites More sharing options...
QuickOldCar Posted May 18, 2015 Share Posted May 18, 2015 I suggest you look up mail in the manual paying attention to the required arguments and structure of headers. Barand posted to the mail section there. Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512154 Share on other sites More sharing options...
grissom Posted May 18, 2015 Share Posted May 18, 2015 (edited) Give this a go : $name = $_REQUEST['applicant_name'] ; $address = $_REQUEST['applicant_address'] ; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/plain;charset=iso-8859-1" . "\r\n"; $headers .= "From: " . $name . "\r\n" ."Reply-To: " . $name . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $success = mail("deleted_for_public_posting_purposes", "Online Job Application", $address, $headers); Edited May 18, 2015 by grissom Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512155 Share on other sites More sharing options...
CroNiX Posted May 18, 2015 Share Posted May 18, 2015 Give this a go : $name = $_REQUEST['applicant_name'] ; $address = $_REQUEST['applicant_address'] ; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/plain;charset=iso-8859-1" . "\r\n"; $headers .= "From: " . $name . "\r\n" ."Reply-To: " . $name . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $success = mail("deleted_for_public_posting_purposes", "Online Job Application", $address, $headers); For the $headers, don't you mean to use $address instead of $name? I assume $address is an email address and $name is a name like "Joe Blow". That might be why this didn't work to begin with. Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512156 Share on other sites More sharing options...
grissom Posted May 18, 2015 Share Posted May 18, 2015 (edited) @CroNix .. er possibly. But looking at the original code, it looked like the variable called $address was actually the body of the e-mail and the variable called $name was the "from" e-mail address ! at least that how it comes across @stjonesMSI - can you just confirm what you are expecting each variable to mean; the names of your variables are somewhat ambiguous, thanks ! Edited May 18, 2015 by grissom Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512158 Share on other sites More sharing options...
stjonesMSI Posted May 18, 2015 Author Share Posted May 18, 2015 (edited) @grissom Yeah - I was just experimenting trying to get a basic SEND to work before finalizing anything - and the variable names are confusing. Will fix it in the final coding. $name = the name of the person from the field "applicant_name" applying for a job, pulled from that form field $address = the street address from the field "applicant_address" where the street address is entered (I am just trying to send one form field for now as the body of the message to try and get the sending to work.) NOT an email address. I did not realize a FROM address (header) was required as pointed out in the manual. Edited May 18, 2015 by stjonesMSI Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512167 Share on other sites More sharing options...
stjonesMSI Posted May 19, 2015 Author Share Posted May 19, 2015 (edited) Just to see if a could get an email to go through, I re-wrote the PHP file as this: <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); $to = 'email_address_here'; $subject = 'this is a test subject'; $message = 'this is a test message'; $headers = 'From: email_address_here'; mail($to, $subject, $message, $headers); ?> So it's not trying to send any field contents - it's just trying to send me a message. Note: everywhere it says "email_address_here" in the actual code there is a legitimate email address. On SUBMIT, I get this error: "Warning: mail(): SMTP server response: 550 5.7.1 Unable to relay for email_address_here in C:\Inetpub\morgansmithllc\send_job_app.php on line 14" Am I correct in understanding that this is something I am going to have to get "fixed" with our email IT folks? Other than the relay issue, should this have successfully sent me the email? Thanks! Steve Edited May 19, 2015 by stjonesMSI Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512222 Share on other sites More sharing options...
grissom Posted May 19, 2015 Share Posted May 19, 2015 (edited) Try this and let me know what happens: $to = your_name@wherever.com ; // EDIT THIS TO YOUR REAL EMAIL ADDRESS $from = valid_email_address@the_same_domain_that_your_php_file_is_on.com // EDIT THIS TOO. THE FROM ADDRESS NEEDS TO BE A VALID E-MAIL ADDRESS // IDEALLY AT THE SAME DOMAIN AS YOUR PHP FILE // SO FOR EXAMPLE IF YOUR PHP file is part of www.foo.com THEN YOU IDEALLY NEED me@foo.com $subject = "Just testing"; $message = "Hello there, here is a test e-mail"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/plain;charset=iso-8859-1" . "\r\n"; $headers .= "From: " . $from . "\r\n" ."Reply-To: " . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $success = mail($to, $subject, $message, $headers); Edited May 19, 2015 by grissom Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512225 Share on other sites More sharing options...
stjonesMSI Posted May 19, 2015 Author Share Posted May 19, 2015 (edited) @girssom, I copied and pasted and put in my email addresses (that should match the domain of the server - both at morgansmithllc.com) and hit SUBMIT. The web page switched to a blank page - but after 15 minites, no email has arrived in my INBOX. Edited May 19, 2015 by stjonesMSI Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512228 Share on other sites More sharing options...
ginerjm Posted May 19, 2015 Share Posted May 19, 2015 Yes - your test email code should work. As for your last post, a blank page usually indicates that you had an error. Check the browser page source, or be sure that you have error checking properly engaged. (See my signature) Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512230 Share on other sites More sharing options...
stjonesMSI Posted May 19, 2015 Author Share Posted May 19, 2015 @ginerjm I have this code at the beginning of the PHP file: ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); I replaced it with the code from your sig to try that. Still just get a blank web apge on SUBMIT. Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512236 Share on other sites More sharing options...
stjonesMSI Posted May 20, 2015 Author Share Posted May 20, 2015 OK - in a holding pattern now. I had been trying to reach our IT person about this all week. Just now got this response: "Ok.. This is starting to make more sense to me now. Phone is enabled on the server.. Not the ability to send email from the server. I can work with you when I get back in town on monday.." So it seems that even though I had confirmed with him in advance that PHP was on ther server and told him what I was needing to do, the server is not set up to send an email using PHP? *sigh* And what the heck is "Phone"? I don't see "Phone" in the PHP manual. So I guess I get to wait til Monday to see if he "turns mail on". *sigh again* Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512291 Share on other sites More sharing options...
CroNiX Posted May 20, 2015 Share Posted May 20, 2015 What are these emails going to be for? Are they critical to your site? Will email go to end users or just internal staff? Email is a very complex beast if you want it to always get to the inbox of the recipient. There are IP reputations to consider, PTR records, RDNS records, SPF record, DKIM, whether your IP (or IP on same subnet) is in a RBL, and several other things that have to be perfect or a lot of ISPs will either reject the email, or put it in spam. If your email is critical, I'd seriously look into services like SendGrid, or even using a GMail (for business) account to send the email through. You don't even need to have an email server as you can use an external SMTP service to send the email through and use a good mailer like PHPMailer instead of the basic mail() function that php supplies. You can spend a lot of time trying to get email right, but unless you're an expert I'd leave it to the experts It's a very complex thing to get right and, no offense, but you seem to be struggling with the basics here. Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512311 Share on other sites More sharing options...
stjonesMSI Posted May 20, 2015 Author Share Posted May 20, 2015 (edited) The email is simply to have the form data from a web page emailed to a single, internal email address here once the user clicks the SUBMIT button on the form. Both the source and destination of that email are on the same domain. That's it. Our IT person has that set up on our parent company website - but not on ours. I realize I am a newbie to PHP and struggling with basics of PHP. But I'm not trying to do anything complex - this should be a fairly simple "starter" project. Just submit a form to an email address. Edited May 20, 2015 by stjonesMSI Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1512314 Share on other sites More sharing options...
Solution stjonesMSI Posted June 5, 2015 Author Solution Share Posted June 5, 2015 OK - the problem was our IT guy had NOT set up PHP on the server to handle emails - even though he said he had. So now things are working and I am chugging along with getting this project to work. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/296376-new-to-php-getting-a-simple-form-to-work/#findComment-1513296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.