Jump to content

php mail finction


Darkmatter5

Recommended Posts

I have Gallery2 installed on my server and it lets you register a user which emails you a message for verification.  I've tried creating a user based website of my own from scratch.  I've tried using the following code to test if the mail() function of PHP is working.

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

If I run the file, Mail Sent. is displayed, but no email is received.  Gallery2 works fine, so either the mail function of php is working, but my code is wrong or Gallery2 uses other means of sending it's email.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/105819-php-mail-finction/
Share on other sites

First, try this and tell us what happens.

 

<?php
$to="[i]my email address here[/i]";
$subject="Test mail";
$message="Hello! This is a simple email message.";
$from="[email protected]";
$headers="From: $from";
$bool = mail($to,$subject,$message,$headers);
if ($bool) {
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>

 

mail() returns a boolean. TRUE if the sending was successful and FALSE if not. make sure it's executing successfully.

Link to comment
https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542317
Share on other sites

@darkwater: I'm not getting defensive. I was just trying to clarify too. Too bad you can't read tone from words ;) Maybe I should use more wink faces when I type.

 

@op: So you added the italics after the fact just for the sake of showing in the post? They are not in your code that you're running when trying to send the mail? Does your host allow you to send mail? I heard a crazy story about a hosting company not letting anyone use the mail function.

Link to comment
https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542366
Share on other sites

Nope the and are not in the code I'm running. In regards to my host letting me send mail, I'm assuming I can as I have Gallery2 in stalled and it uses a user registration system that sends the user an email for activating their account.  Gallery2 is on the same server, and it works for Gallery2, so either my code is wrong or Gallery2 sends mail via other means.

Link to comment
https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542391
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.