Mail function, need a little help.

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

Post Reply
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

Mail function, need a little help.

Post by mattyboi »

Hey guys,

I am new to this forum as well as PHP, so forgive me if this is a noob question. I used the search and tried everything I thought might be helpful but I was unsuccessful. Anyway I am just trying to send a simple email using the "mail()" fuction.

Code: Select all

<?php
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Mail it
mail("matt@sks.com", "hello", "test" ,$headers);
?>
Also, do I need any other files to make the mail() function work.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mail() can require several things depending on your installation. It will want a proper SMTP setting on Windows machines. It may (often does) require a From in your headers. It may not even be able to send the mail because your host disallows its users to generate emails outside of their servers. The destination may reject the email due to "bad" headers, or it just doesn't like you, or more likely, your server.

We often recommend using phpMailer instead to help quickly fix these problems and give you added functionality.
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

using yahoo, php.ini??

Post by mattyboi »

Thanks, I am not quite sure what do do with this though. In the instructions it tells me to edit the php.ini file. I don't know where that file is. Also I am using http://www.yahoo.com as my domian provider. Maybe that has something to do with it.

Thanks a lot.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

create a blank page with this code

Code: Select all

<?php
phpinfo();
?>
near the top it will say the path to your PHP.ini, copy, open up explorer, paste in address, make changes (Mail is about 2/3rd down)

go to run->type "net stop apache" without quotes -> cmd prompt should popup and close
go to run->type "net start apache" without quote

try again
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

Problem Solved.

Post by mattyboi »

I solved the problem. When hosted by Yahoo, you have to turn the PHP mail function on.

Stupid Yahoo

Thanks for the help guys
Post Reply