Send email from PHP

Reply

Join Date: Jul 2008
Posts: 21
Reputation: enzogoy is an unknown quantity at this point 
Solved Threads: 0
enzogoy enzogoy is offline Offline
Newbie Poster

Send email from PHP

 
0
  #1
Oct 27th, 2008
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:
  1. $fromEmail = "admin@domain.com";
  2. $subject = "Welcome";
  3. $body = "Hi,\n\nYou have visited the page.";
  4. if (mail($Email, $subject, $body, "From: $fromEmail")) {
  5. echo("<p>Message successfully sent!</p>");
  6. } else {
  7. echo("<p>Message delivery failed...</p>");
  8. }

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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: Send email from PHP

 
0
  #2
Oct 27th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: DNS is an unknown quantity at this point 
Solved Threads: 0
DNS DNS is offline Offline
Newbie Poster

Re: Send email from PHP

 
0
  #3
Oct 27th, 2008
This code should work.
  1. <?php
  2. $to = 'nobody@example.com';
  3. $subject = 'the subject';
  4. $message = 'hello';
  5. $headers = 'From: webmaster@example.com' . "\r\n" .
  6. 'Reply-To: webmaster@example.com' . "\r\n" .
  7. 'X-Mailer: PHP/' . phpversion();
  8.  
  9. $check = mail($to, $subject, $message, $headers);
  10. if($check)
  11. {
  12. echo "mail sent successfully. ";
  13. }
  14. else
  15. {
  16. echo "Faid to sent. ";
  17. }
  18. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 21
Reputation: enzogoy is an unknown quantity at this point 
Solved Threads: 0
enzogoy enzogoy is offline Offline
Newbie Poster

Re: Send email from PHP

 
0
  #4
Oct 27th, 2008
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
Last edited by enzogoy; Oct 27th, 2008 at 7:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 7
Reputation: BrettH is an unknown quantity at this point 
Solved Threads: 1
BrettH's Avatar
BrettH BrettH is offline Offline
Newbie Poster

Re: Send email from PHP

 
0
  #5
Oct 27th, 2008
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
Interested in Surfing? Check out World Surf Engine.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: Send email from PHP

 
0
  #6
Oct 27th, 2008
From PHP >= 4, it may have already been installed.

Just try including Mail.php.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 21
Reputation: enzogoy is an unknown quantity at this point 
Solved Threads: 0
enzogoy enzogoy is offline Offline
Newbie Poster

Re: Send email from PHP

 
0
  #7
Oct 27th, 2008
I have version 5.+ install on my server therefor I dont need to install anything right?

I use the code below:
  1. include("Mail.php");
  2.  
  3. $from = "Admin <admin@domain.com>";
  4. $to = "user <user@domain.com>";
  5. $subject = "Hi!";
  6. $body = "Hi,\n\nHow are you?";
  7.  
  8. $host = "exchange.domain.com";
  9. $username = "admin";
  10. $password = "adminpassword";
  11.  
  12. $headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
  13. $smtp = Mail::factory('smtp',array ('host' => $host,'auth' => true,'username' => $username,'password' => $password));
  14.  
  15. $mail = $smtp->send($to, $headers, $body);
  16.  
  17. if (PEAR::isError($mail)) {
  18. echo("<p>" . $mail->getMessage() . "</p>");
  19. } else {
  20. echo("<p>Message successfully sent!</p>");
  21. }

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

enz
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: Send email from PHP

 
0
  #8
Oct 27th, 2008
What is the error message?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 21
Reputation: enzogoy is an unknown quantity at this point 
Solved Threads: 0
enzogoy enzogoy is offline Offline
Newbie Poster

Re: Send email from PHP

 
0
  #9
Oct 27th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 21
Reputation: enzogoy is an unknown quantity at this point 
Solved Threads: 0
enzogoy enzogoy is offline Offline
Newbie Poster

Re: Send email from PHP

 
0
  #10
Oct 28th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1601 | Replies: 13
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC