PHP Email Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

PHP Email Problems

Post by phpunleashed »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is probably a really stupid question that should be answered easily.  I have been scouring Tutorials and How Tos for days now and have been reluctant to submit a new post it in any forums for fear of someone having a one sentence answer, then continuing on for pages on how they pwned me and i'm such a noob.

Anyways here goes.  I have created an online form for an application and the form works fine, it has a subsequent page that shows what information they have entered and it stores it all into a database quite nicely.  My problem is that it will not email.

Here is some of the relevant code for the email:

Code: Select all

$message = stripslashes($message);
$mail_path = "/usr/sbin/sendmail -t" ;

mail("info@example.com","Application Form .$firstname. .$lastname.",$message,"From: $email");
$to_put .= $FirstName."|".$LastName."|".$MiddleI."|".$Address."|".$Suite."|".$City."|".$State."|".$ZipCode."|".$Email";
Database is working fine, but I thought I would include it for kicks:

Code: Select all

$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $FirstName."|".$LastName."|".$MiddleI."|".$Address."|".$Suite."|".$City."|".$State."|".$ZipCode."|".$Email";
fwrite($make,$to_put);
Let me know what information you need to diagnose the problem.
Thanks


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Email Problems

Post by RobertGonzalez »

Not much of a change, but try this.

Code: Select all

<?php
$message = stripslashes($message);

// Is this used anywhere?
$mail_path = "/usr/sbin/sendmail -t" ;

// try some error checking
if (!mail('info@example.com', 'Application Form ' . $firstname . ' ' . $lastname, $message, 'From: ' . $email))
{
    echo 'Could not send the mail';
}
?>
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Could not send the mail

Post by phpunleashed »

I put in the error checking you suggested and it came up. Am I not calling my sendmail correctly? I am very new to PHP so I am probably missing something really obvious.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

According to the PHP manual on mail():
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
What that means is that you mail server is not accepting the mail for delivery.
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Post by phpunleashed »

is there an easy way to do that? Get my mail server to accept it? I am looking into it.
Thanks for the fast help.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Have you got sendmail installed on the server?
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Post by phpunleashed »

yes, sendmail is installed
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Also, is this a local server or a hosted server?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

send mail through any other application from that server can you?
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Post by phpunleashed »

It is a hosted server, and sendmail is working great for everything else.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Run a simple test hard coding the params into the function along with an error trap. See if that does anything. I doubt it will, but for problem solving purposes, start simple and work outward.
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Post by phpunleashed »

Thanks for all the help, btw i posted that incorrectly that my server was hosted... it's really local. My weekend starts now so i'll be back monday stewing over it. If you have any other ideas come over the weekend these posts are helping me get closer to the problem.
Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If it is a local server I would guess that sendmail is not installed/configured. You may want to check that first before trying anything else code-wise.
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Post by phpunleashed »

These are the errors I am getting in my sendmail logs:

Code: Select all

Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279: from=apache, size=1120, class=0, nrcpts=1, relay=apache@localhost
Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279:   0: fl=0x0, mode=10600: FIFO: dev=0/5, ino=23777300, nlink=1, u/gid=48/48, size=0
Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279:   1: fl=0x1, mode=20666: CHR: dev=0/13, ino=1869, nlink=1, u/gid=0/0, size=0
Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279:   2: fl=0x2, mode=20666: CHR: dev=0/12, ino=174, nlink=1, u/gid=0/0, size=0
Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279:   3: fl=0x2, mode=140777: SOCK localhost->[[UNIX: /dev/log]]
Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279:   4: fl=0x1, mode=20666: CHR: dev=0/13, ino=1869, nlink=1, u/gid=0/0, size=0
Oct  9 09:36:20 chief02 sendmail[30279]: k99FaKmp030279: SYSERR(apache): queueup: cannot create queue file ./qfk99FaKmp030279, euid=48, fd=-1, fp=0x0: Permission denied
~
phpunleashed
Forum Newbie
Posts: 8
Joined: Fri Oct 06, 2006 1:56 pm
Location: SLC, UT

Post by phpunleashed »

Does anyone know where i could configure the php form to use a different address instead of apache@localhost or to how to allow apache@localhost permission?
Thanks
Post Reply