aschulz90 Posted July 10, 2008 Share Posted July 10, 2008 Hi, Im somewhat new to PHP, but my boss gave me the task of fixing a PHP page which is supposed to submit data to both a MySQL server and to two emails (the one who generated the report and the one recieving it.) I've finally narrowed down what segment of code was causing the problem (the page would not redirect to the error or success page, it would just sit on the scripting page). It was the section which sent the email. I looked up the syntax and looked in a book and it looks the same just manages to be neater and more impressive (to me.) can you see why it won't send an email? If it is not the syntax what configuration files might be at fault, thanks for any help. the code is attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/ Share on other sites More sharing options...
Guest Xanza Posted July 10, 2008 Share Posted July 10, 2008 Looks kinda screwed... I suggest just re-writing it from the ground up... Not too hard. Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-586579 Share on other sites More sharing options...
dannyb785 Posted July 10, 2008 Share Posted July 10, 2008 A couple things... what is FilterCChars? why do you have -lvincent@ci.durham.nh.us in the additional parameters of the first email? on the line that says "$emailFrom = FilterCChars("$FTGemail");" where is the FTGemail variable? the main reason I think it's not working is because in your first email, you have the headers set to say "From: USER WHO SUBMITTED DATA". Thing is, that user won't have the same email domain as your domain(i.e. if you are drainage.com, he might have submitted something@gmail.com) and I know many servers won't send email if the "From" is not the current domain. Cuz think, you could send an email pretending to be someone else to do phish attacks... and those aren't very nice! My suggestion. Replace the $emailfrom variable with "donotreply@YOURDOMAIN.com" where YOURDOMAIN is the domain of the website that the info is being submitted on. Give that a try. If no luck, then come back here. Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-586580 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I don't feel like downloading it, so can you just post the relevant code please? Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-586582 Share on other sites More sharing options...
Guest Xanza Posted July 10, 2008 Share Posted July 10, 2008 Posted for the lazy among us. <?php # Email to Form Owner $emailSubject = FilterCChars("Project Storm Drain response"); $emailBody = "The following information has been provided from a visitor to the Project Storm Drain web page. Please note that if the checkbox item contains a \"yes\" answer, the visitor would like a reply from DPW.\n" . "\n" . "firstname : $FTGfirstname\n" . "lastname : $FTGlastname\n" . "email : $FTGemail\n" . "address1 : $FTGaddress1\n" . "city : $FTGcity\n" . "State : $FTGState\n" . "zip : $FTGzip\n" . "homephone : $FTGhomephone\n" . "workphone : $FTGworkphone\n" . "locationaddress : $FTGlocationaddress\n" . "intersectionorlandmark : $FTGintersectionorlandmark\n" . "characteristics : $FTGcharacteristics\n" . "checkbox : $FTGcheckbox\n" . "Submit : $FTGSubmit\n" . "MM_insert : $FTGMM_insert\n" . ""; $emailTo = 'aschulz90@gmail.com'; $emailFrom = FilterCChars("$FTGemail"); $emailHeader = "From: $emailFrom\n" . "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=\"ISO-8859-1\"\n" . "Content-transfer-encoding: 8bit\n"; ini_set("sendmail_from";"lvincent@ci.durham.nh.us"); mail($emailTo, $emailSubject, $emailBody, $emailHeader,"-lvincent@ci.durham.nh.us"); #Confirmation Email to User $confEmailTo = FilterCChars($FTGemail); $confEmailSubject = FilterCChars("Project Storm Drain information received "); $confEmailBody = "Thank you for providing the Town of Durham with information pertaining to Project Storm Drain. We will look into the information you provided. If you checked the follow-up box, someone from the DPW will soon be in touch.\n" . "\n" . "Please do not respond to this message, as it is an automated reply. If you wish to contact the DPW directly, please email dkdkdkd.\n" . ""; $confEmailHeader = "From: dcedarholm@ci.durham.nh.us\n" . "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=\"ISO-8859-1\"\n" . "Content-transfer-encoding: 8bit\n"; mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-586588 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2008 Share Posted July 10, 2008 This code looks like it was written with register_globals enabled in mind. Register_globals hasn't been enabled as the default in many years (4 or 5). So that's probably the first problem. Ken Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-586596 Share on other sites More sharing options...
aschulz90 Posted July 11, 2008 Author Share Posted July 11, 2008 So here's what I know after additional troubleshooting: Variable names do not matter, All scripting except the email portion works, for sure. here's the part where I think you guys can help: NO mail script works: I tried doing a simple email page which would just email me at my personal email. It did not work... and I'm almost certain that after all my attempts and views at various websites it wasn't the code. So what in the PHP.ini file would effect whether you could send emails or not? Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-587853 Share on other sites More sharing options...
dannyb785 Posted July 11, 2008 Share Posted July 11, 2008 So here's what I know after additional troubleshooting: Variable names do not matter, All scripting except the email portion works, for sure. here's the part where I think you guys can help: NO mail script works: I tried doing a simple email page which would just email me at my personal email. It did not work... and I'm almost certain that after all my attempts and views at various websites it wasn't the code. So what in the PHP.ini file would effect whether you could send emails or not? Did you even look at my post? 99% of the time, it is because the mail function is sending with the header saying "From: someone@someotherdomain.com" And your function does just that. Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-587876 Share on other sites More sharing options...
aschulz90 Posted July 11, 2008 Author Share Posted July 11, 2008 Hey Dannyb, sorry I didn't acknowledge your post. I did however read it and tried what you send to no avail. I think that you are partly correct however, I found the php.ini file on the web server and found the mail function settings. I think I have found the portion of code that was not in use which...needed to be, I will keep you updated, thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-587879 Share on other sites More sharing options...
dannyb785 Posted July 11, 2008 Share Posted July 11, 2008 I'm gonna say that you need to strip away all code except the mail() function. just have <?php mail() ?> and that be it. And put the literal strings in the mail function. So do <?php if(mail("testuser@whatevermail.com", "Test email", "This is a test", "lvincent@ci.durham.nh.us")) echo "Email sent"; ?> this is assuming that the domain you're sending the email from is nh.us. And replace testuser with your email(or an email you have access to) If this doesn't work, then you have server issues with the mail function Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-587887 Share on other sites More sharing options...
Guest Xanza Posted July 11, 2008 Share Posted July 11, 2008 mail() is prolly turned off on your server. lol. Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-587900 Share on other sites More sharing options...
aschulz90 Posted July 14, 2008 Author Share Posted July 14, 2008 Okay, after much strange work I got the code to work! for the most part... The mail function will not send the confirmation email to the user unless it ends with @ci.durham.nh.us so the code: <?php ini_set('SMTP', 'mail.ci.durham.nh.us'); ini_set('smtp_port', '25'); $to = "aschulz@ci.durham.nh.us"; #<---CHANGE THAT TO: xxx@gmail.com or xxx@yahoo.com, it doesn't work...why? $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; ini_set("sendmail_from", "noreply.durham.nh.us"); if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-589658 Share on other sites More sharing options...
dannyb785 Posted July 14, 2008 Share Posted July 14, 2008 The mail function will not send the confirmation email to the user unless it ends with @ci.durham.nh.us isn't that what my first post said??? I have a feeling you didn't try it when I suggested it because now you're saying it as if it's something you discovered on your own and don't understand why. Well, read my first post and you'll see why! Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-589816 Share on other sites More sharing options...
aschulz90 Posted July 21, 2008 Author Share Posted July 21, 2008 Dannyb I feel alot of hostility, anyways it was a problem with the configuration of our mail server, no fault of php or the programmers! anyways thank you all you have all helped me get started in .php and it is now my prefered web language (gave asp.net a shot and didn't like it). This thread is resolved... Quote Link to comment https://forums.phpfreaks.com/topic/114123-solved-email-function-not-working-yet-perfect-coding/#findComment-595429 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.