| | |
Send email from PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 21
Reputation:
Solved Threads: 0
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:
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
Here is the code:
PHP Syntax (Toggle Plain Text)
$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
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
This code should work.
PHP Syntax (Toggle Plain Text)
<?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. "; } ?>
•
•
Join Date: Jul 2008
Posts: 21
Reputation:
Solved Threads: 0
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
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
Last edited by enzogoy; Oct 27th, 2008 at 7:25 pm.
Here is the official PEAR MAIL page.
http://pear.php.net/package/Mail
and here is the link to download mail.php
http://download.pear.php.net/package/Mail-1.1.14.tgz
http://pear.php.net/package/Mail
and here is the link to download mail.php
http://download.pear.php.net/package/Mail-1.1.14.tgz
Interested in Surfing? Check out World Surf Engine.
•
•
Join Date: Jul 2008
Posts: 21
Reputation:
Solved Threads: 0
I have version 5.+ install on my server therefor I dont need to install anything right?
I use the code below:
and I have an error in programming. Am I doing something wrong in there?
enz
I use the code below:
PHP Syntax (Toggle Plain Text)
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
•
•
Join Date: Jul 2008
Posts: 21
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- PHP Sendmail Tutorial (PHP)
- AJAX Send Email Form with prototype and PHP (JavaScript / DHTML / AJAX)
- Automatically send email in php without user interaction (PHP)
- Send an Email in PHP (PHP)
- Send email through php? (PHP)
- Need Help Making a Form send to an email using PHP (PHP)
- Using PHP to Send Email to a single DB list member every 24 hrs. (PHP)
- PHP Email (PHP)
Other Threads in the PHP Forum
- Previous Thread: Mail Server run in local host but cant use Mail() Function
- Next Thread: Auto button when user hits the Enter key
Views: 1601 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






