8 Replies - 996 Views - Last Post: 09 September 2013 - 09:37 AM

#1 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

sending email working from terminal but not the web

Posted 06 September 2013 - 02:14 PM

ok here is my issue i have a very simple email script on our server and after many long days fooling with it i can get it to read the script and send the email from the terminal by forcing executing of the php script with
[[email protected]]$ php emaitest.php

but if i go to the web page this is displayed at it will not actually send the mail from the browser everything i can tell the script is executing just fine just not from the browser for some reason it only will send from the terminal.
i know its not my directory or my user permissions i have two other email scripts that are instigated from the browser working just fine. and i copied as much as i could salvage from the working scripts to try to make my newest script work but with no luck this is where im stuck at.
here is the script in question:
<?php
// File Name: emailtest.php
// Dependencies: none

$to = "[email protected];
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:[email protected]";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>


i have set my file permissions to 755 on all files just to try to correct this issue and i have made sure apache is the owner of the file just like the other two scripts that are running just fine, so im actually stumped here i want to say its a machine issue but i know that cant be true. any ideas?

This post has been edited by CodeCapition1: 06 September 2013 - 02:16 PM


Is This A Good Question/Topic? 0
  • +

Replies To: sending email working from terminal but not the web

#2 ccubed   User is offline

  • It's That Guy
  • member icon

Reputation: 164
  • View blog
  • Posts: 1,416
  • Joined: 13-June 08

Re: sending email working from terminal but not the web

Posted 06 September 2013 - 02:17 PM

Something I ran into before on a server is that the server I was on would only accept things this way:

mail($to,$subject,$message,"From:[email protected]");



In my case, the host server would absolutely not send any email unless I had typed out the From in the headers explicitly. It wouldn't let me allocate it dynamically. Something to try.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4201
  • View blog
  • Posts: 13,273
  • Joined: 08-June 10

Re: sending email working from terminal but not the web

Posted 06 September 2013 - 02:18 PM

what value does the mail() function return?

note: mail() gives no guarantee that the mail is actually sent, only that the CLI sendmail (or related) binary is called.
Was This Post Helpful? 0
  • +
  • -

#4 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: sending email working from terminal but not the web

Posted 06 September 2013 - 02:25 PM

well i tried changing the header like you suggested and no improvment. worth a try though.
as far as the return value i am unsure. how would i go about finding that out
Was This Post Helpful? 0
  • +
  • -

#5 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: sending email working from terminal but not the web

Posted 06 September 2013 - 04:36 PM

Capture it in a variable and then test it using a IF statement. If it's true, then PHP managed to pass the email onto the SMTP client. If it's false, then it failed to do so.

View Postccubed, on 06 September 2013 - 09:17 PM, said:

In my case, the host server would absolutely not send any email unless I had typed out the From in the headers explicitly. It wouldn't let me allocate it dynamically. Something to try.

That doesn't make any sense. There is absolutely no difference between assigning a string to a variable and passing that variable into the function, and putting the string directly into the function. Both ways PHP is creating a string in memory and passing a reference to that string into the function. The first version is just cleaner.

There must have been some other cause. A typo maybe, or a conflicting variable name?
Was This Post Helpful? 1
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6642
  • View blog
  • Posts: 30,931
  • Joined: 10-May 07

Re: sending email working from terminal but not the web

Posted 06 September 2013 - 04:39 PM

It's possible that if you are sending from a residential IP, your ISP saw the first one (or few) go through & then blocked future traffic.

Also depends on where you are sending, it could be getting spammed out, again because it's from a residential IP.

Troubleshooting email on PHP is tricky because of what Dormilich pointed out, there is no guarantee from PHP of delivery. It isn't an MTA, just sends traffic.
Was This Post Helpful? 1
  • +
  • -

#7 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: sending email working from terminal but not the web

Posted 09 September 2013 - 08:46 AM

I appreciate everyone's help and thoughts. as for the IP address issue i dont think that is the issue the ISP i work for is very aware of what im trying to do so i dont believe they would block the port they are asking me to use. the networking head is solid in his belief that its my code and nothing else i dont want to call him wrong but he admits he is not a programmer and insists if one works they all should work so it has to be me. anyway he will be gone for a few days so im going to try to get this working befor then if not i will make him make me a basic script that does work and i will use that. im going to look in to other methods of sending email from my web page. again thanks for all your help
Was This Post Helpful? 0
  • +
  • -

#8 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: sending email working from terminal but not the web

Posted 09 September 2013 - 09:03 AM

If you have root, be sure to check out the php ini files. If you've used aptitude for the install, the cli and http run different settings which could cause issues.
Was This Post Helpful? 1
  • +
  • -

#9 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4201
  • View blog
  • Posts: 13,273
  • Joined: 08-June 10

Re: sending email working from terminal but not the web

Posted 09 September 2013 - 09:37 AM

instead of the somewhat unreliable mail() function you could use one of the mailing libraries (e.g. SwiftMailer)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1