I just create a php page where user will enter their name in then the page will send them an email with a few word in the body message.

Here is the code:

$fromEmail = "admin@domain.com"; 
$subject = "Welcome";
$body = "Hi,\n\nYou have visited the page.";
if (mail($Email, $subject, $body, "From: $fromEmail")) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }

I even try not to include "From: $fromEmail") in the mail() but still not success. All I receive is "Message delivery failed...".

In the php.ini, I follow the setup in http://au.php.net/manual/en/mail.configuration.php.

** $Email is the variable which will obtain the user email. I even replace that variable with a valid email but the same story.

Do I have to include something?

Thank you.
Enz

Does your server require authentication? (logging in before you can send)

If it does, you have to use the PEAR set of email methods, because mail() does not support SMTP authentication.

This code should work.

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$check = mail($to, $subject, $message, $headers);
if($check)
{
echo "mail sent successfully. ";
}
else
{
echo "Faid to sent. ";
} 
?>

Hi DNS, your codes are not much different to mine and both are not working (I tried yours). I think scru is right. Now I have to look at the PEAR email stuff.

I am always in trouble of using PEAR stuff and never success before. I just don't have any idea how PEAR works. I google and found out that I have to include mail.php in the code but where to download it. Could you please help me to make this work.

Thank you.
Enz

From PHP >= 4, it may have already been installed.

Just try including Mail.php.

I have version 5.+ install on my server therefor I dont need to install anything right?

I use the code below:

include("Mail.php");

$from = "Admin <admin@domain.com>";
$to = "user <user@domain.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "exchange.domain.com";
$username = "admin";
$password = "adminpassword";

$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$smtp = Mail::factory('smtp',array ('host' => $host,'auth' => true,'username' => $username,'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}

and I have an error in programming. Am I doing something wrong in there?

enz

What is the error message?

It is the HTTP 500 Internal Server Error

Most likely causes:
The website is under maintenance.
The website has a programming error.


*** I think there is a problem with the code.

I try severals email function but all end up with this error:

This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.

For more information about HTTP errors, see Help.

I'm still not able to send mail, please help me out.

Thank you
enz

$fromEmail = "admin@domain.com"; 
$subject = "Welcome";
$body = "Hi,\n\nYou have visited the page.";
$sent=mail($Email, $subject, $body, $from) ;
if($sent)
{
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }

Hmm, maybe the PEAR mail extensions weren't installed. Do a page with just this code:

<?php include "Mail.php"; ?>

If you still get that error, then you need to manually install the mail extensions

Hi scru,

Yeah, I'm in trouble of install the PEAR mail extensions. I download the file down and get into the commnd line. I use this command but it doesn't seem to do anything.

C:\PHP\pear install -o mail-1.1.14

Could you please show me hwo to install it manually.
Thank you.
Enz

I also facing the same problem !!

Please help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.