Jump to content

Recommended Posts

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]

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.

Guest Xanza

Posted for the lazy among us. :P

 

<?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);


?>

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?

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.

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.

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

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>");
}
?>

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!

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...

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.