mail()

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

User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

mail()

Post by C_Calav »

Hi guys,

im trying to code this mail() for the first time.

i got this error, and did some google'n and saw that i was missing the from parameter. i put it in and still got the error.

here is my error:
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Apache2\htdocs\survey\launch_email.php on line 46
and here is my code so far:

Code: Select all

<?php


$mailto = "***";
$subject = "Thank you for signing up for our conference";
$body = "Hello Chris!";
$from = "Your Name <youremail@yourdomain.com>";


mail($mailto,$subject,$body,$from); 


?>
thanx

PS: for some reason i cannot use the search on this site properly when i am at work?

at home it works fine but at work when i seach and click on a link it goes to a blank white page. very weird. it has nothing to do with a fire wall or blocking of sites etc.
Last edited by C_Calav on Mon Mar 27, 2006 4:03 pm, edited 3 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you didn't specify the "From: " part.. :P
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

is this better?

still getting same error

Code: Select all

<?php

$mailto = "***";
$subject = "Thank you for signing up for our conference";
$body = "Hello Chris!";
$headers = "From: C C <***@hotmail.com>"; 

mail($mailto,$subject,$body,$headers); 

?>
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Apache2\htdocs\survey\launch_email.php on line 46
Last edited by C_Calav on Mon Mar 27, 2006 4:04 pm, edited 1 time in total.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

PS: im in a localhost enviroment, does that make a difference?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What happens if you take out the name in your from field and just leave a plain old email address?. Also try adding

Code: Select all

"\r\n"
to the end of the $headers.

I know it shouldn't make a difference but it's possible there's a bug... have you got the sendmail_from value defined in php.ini?

Grrr... feyd's filter got me :lol: 'R'
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

hi d11wtq,

i have not touched my php.ini file, it is

;sendmail_from = me@example.com

at the moment. do i need to change it?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It shouldn't really matter if you specify your own headers but give it a go .... just uncomment it. Also if you haven't touched PHP.ini you probably need to set up your smtp settings before mail() will work ;-)
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

so i can use the mail() and test to see if eveything is working ok? thats good.

how should i setup my php.ini file?

is there a certain way for localhost? or a link i can have a read of or something?

this is what i got so far, just default
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com
thanx
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

uncomment

;sendmail_from = me@example.com
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Is your smtp server running on localhost? If it is then that all would be good but otherwise you need to specify the smtp provided by your ISP..

This is mine
[mail function]
; For Win32 only.
SMTP = smtp.ntlworld.com
smtp_port = 25

; For Win32 only.
sendmail_from = xxxxxxx@ntlworld.com
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

ok i have setup my php.ini file.

the file was wunder c:/winnt/php.ini

that is the correct location of the php file right?


still get the same error with this setup.

what else could be wrong?
[mail function]
; For Win32 only.
SMTP = puccini.steel.xxxxx
smtp_port = 25

; For Win32 only.
sendmail_from = postmaster@xxxx
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Did you try \r\n after the header and removing the name and < >? That should be your php.ini yes but run php_info() to check. You can also see what it's reading as your mail settings too.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

ok i will do those changes and let you know.

one more question, i had a look at my info.php file and the

SMTP says localhost

and sendmail_from says no value.

now i just changed them both before why is this?

thanx
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What does this line say in the output?
Configuration File (php.ini) Path C:\WINDOWS\php.ini
If it's c:\winnt\php.ini it's ok then i'd look further down your ini file... it must be overwriting the values somewhere
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Make sure you have an SMTP server installed on your windows machine.
Post Reply