Jump to content

Recommended Posts

Had the following code working for months and now its not working anymore???  I dont't think the code is the correct way to do it but it did work, Can someone please look at it or give me the correct code.  All I am trying to do is take the data from the form and email it to an email address and cc the user that filled out the form.  I would like to add a bcc in the future.  Here is my current code 

 

<?php
$email = $_POST['EMAIL'];
$mailto = "user@domain.com, user@domain.org";
$mailhead = "FROM: LOI<user@domain.org>"."\r\n";
$mailhead .= "Reply-To: user@domain.org"."\r\n";
$mailhead .= "CC: ".$email;
$mailbody = "Values submitted from LOI:\n";
while (list($key, $val) = each ($HTTP_POST_VARS)) {	
$mailbody .= "$key : $val\n";
}
mail($mailto, $mailsubj, $mailbody, $mailhead);

header("LOCATION: letter.html");
?>

 

 

 

(my file structure is the following.  inquiry.html has a form and the submit button goes to letter.php(code above) then it directs to letter.html)

 

 

Thanks

Trevor

Link to comment
https://forums.phpfreaks.com/topic/217571-php-sendmail-stopped-working-help/
Share on other sites

 

.....
while (list($key, $val) = each ($HTTP_POST_VARS)) {	
...
?>

 

Depending on your PHP version ... (in case you recently upgrade PHP)

HTTP_POST_VARS was deprecated long time ago and you should use $_POST instead.

 

if you include this lines at the begining of your code you should see a notice/warning message.

 error_reporting(E_ALL); 
ini_set("display_errors", 1);

 

 

added that code to beginning and I get the following error

 

Notice: Undefined variable: mailsubj in /home/trevor/public_html/letter.php on line 12

 

Warning: Cannot modify header information - headers already sent by (output started at /home/trevor/public_html/letter.php:12) in /home/trevor/public_html/letter.php on line 14

 

 

Not really good at code so if someone could redue my code with the updated code that would be great.  thanks!!

Notice: Undefined variable: mailsubj in /home/trevor/public_html/letter.php on line 12

 

this error is very clear and you should be able to fix it for yourself.

 

for this warning:

Warning: Cannot modify header information - headers already sent by (output started at /home/trevor/public_html/letter.php:12) in /home/trevor/public_html/letter.php on line 14

 

try deleting the blank line before "header"

ok made all those changes and now no errors or warnigns come up but still no emails, here is the updated code

 

<?php
error_reporting(E_ALL);  ini_set("display_errors", 1);
$email = $_POST['EMAIL'];
$mailto = "user@domain.com, user@domain.org";
$mailhead = "FROM: LOI<user@domain.org>"."\r\n";
$mailhead .= "Reply-To: user@domain.org"."\r\n";
$mailhead .= "CC: ".$email;
$mailbody = "Values submitted from LOI:\n";
$mailsubj = "Letter of Inquiry";
while (list($key, $val) = each ($_POST)) {	
$mailbody .= "$key : $val\n";
}
mail($mailto, $mailsubj, $mailbody, $mailhead);
header("LOCATION: letter.html");
?>

Any other ideas?  not getting any warnings now but emails are still not showing up, I have tried lots of different email address's so I know it is not on the receiving end.  really need to figure this out for customer.

 

Thanks for all the help and quick replys... I really appreciate it!!

 

T

Change your mail() line of code to the following -

 

if(mail($mailto, $mailsubj, $mailbody, $mailhead)){
    echo "success";
} else {
    echo "mail function call failed";
}

 

and temporarily comment out the header(); redirect statement (so that you can be sure to see either the success or mail function call failed message.)

 

You will probably need to check with the web host to see what is happening on the sending mail server with the emails you are trying to send. You should probably check with the web host anyway to see if anything has been changed with the configuration needed for a php script to send email.

 

Sadly, the contents of the $email variable is being put directly into the header field without any validation, so it is possible that spammers have been sending email through the mail server and your mail server has been banned by wherever you are trying to send the emails to.

restarted the service and restarted apache

 

^^^ Sounds like this is either VPS or dedicated hosting? What sort of administrative access do you have to the mail server? The type of MTA does not directly matter as long as it is configured to accept emails from the web server/php.

 

Is the php.ini sendmail path (which is just the path to the MTA binary/cli) set correctly?

 

You would likely need to look at the 'send' queue to see what is happening to the emails. Are they being placed into the queue? Are they getting sent to the destination?

 

Any chance someone change the 'relaying' settings of the mail server so that it no longer accepts any emails from the web server/php?

yes it is a vps, I have root access to the server.  I see manage mail queue and no messages show up.  I will see if I can find a relay setting and the php.ini.  thanks for your help....this is so crazy!

 

looked at php.ini and for sendmail path I have            /usr/sbin/sendmail -t -i  dont know if that means anything.  just verified with winscp that the sendmail file is there.

 

 

thanks

should I just restore exim to default settings?

 

Probably NOT. (Only if you have ALL the current settings recorded.)

 

Is this mail server used for any other thing, such as email clients/web based mail interface connecting to it and using it to send/receive email and it works?

 

 

Does webmail exist and work on the domain where your php script does not work at?

 

The latest version of exim apparently uses an access control list to determine who/what can send emails through it.

 

Normally, a MTA is setup to TRUST the IP address of the web server/php. This satisfies the relaying restrictions and the MTA will accept an email from the php mail() function (which looks like an unauthenticated mail client) and if your script previously worked as written this is(was) likely the case.

 

Given that your php script does not generate any php errors at the mail() function (though it would require that the MTA be configured to give error back to php) it is likely that the MTA is accepting the emails and it is just a matter of finding out where they are or are not going to.

I suppose webmail does exist all though I have no users setup or tested it.  ( i will setup and test) UPDATE: webmail works, just setup and tested

A couple things..

 

I have found out that my vps is on 1 ip address and the website I am having issues with is on a different ip address, I was told that the server can have more than 1 ip address and have verified this in vps accounts. 

 

I also found out that one of the other users on a different domain with email opened a ticket about spam email and they made a spf record so I removed the spf record and restarted services to see if it fixed it but no luck....

 

So I think it is def a hosting.com issue and thanks to you guys I think I have the info to keep them from telliing me its a code problem... Will keep this post updated.

 

Thanks

Fixed it!!!

 

So I took my files and uploaded them to my personal linux godaddy account and the emails worked, So then I called hosting.com and they stayed on the phone with me and went through every setting in the vps. What happened was my junior tech opened a ticket because 1 domain was getting tons of spoofed spam emails so the hosting tech turned on this setting in the "Tweak Settings"

 

Prevent the user "nobody" from sending out mail to remote addresses (PHP and CGI scripts generally run as nobody if you are not using PHPSuexec and Suexec respectively.)

 

Problem was the tech never documented this so the tech I got on the phone last only saw "made change" in the notes but he was awesome and found it, unchecked and bam email is working again. 

 

Thanks again everyone for all the help!!! you guys saved me again!!!

 

 

T

  • 1 month later...

back again!!  So this is related so I figured I would keep the same post so you could see history.  So once I changed the tweak setting "prevent nobody from sending email" back to off I was able to get my send email working again but now one of my users is getting about 20 spoofed emails a day!  if I turn the setting back on the spam emails stop but my sendmail forms stop working.  So I guess I need some help, is there a better way to do the send mail  code that requires auth?  please help

 

Thanks!!

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.