zero-perfoliate
zero-perfoliate

Author Topic: Email PHP script  (Read 1725 times)

Offline nkosinathi

  • PHP Workers
  • **
  • Posts: 8
  • Karma: +0/-0
Email PHP script
« on: October 02, 2008, 09:52:08 PM »
I have downloaded every php email script i can find on the net and followed it to the letter. All i get when i try to send email from my website is an indication that the email has been sent successful but there is no email sent. Please help before i lose all my hair (not that there is a lot left).

<?php

$from = "me@example.com";
$to = "me2@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "myloginname";
$password = "mypassword";

$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>");
 }
?>

icestormz

  • Guest
Re: Email PHP script
« Reply #1 on: October 02, 2008, 11:23:08 PM »
Why are you doing it that way? why not just use a simple form mail php script, its much easier.

Writing the Feedback Form

The first thing we need to do is to write the feedback form itself. Put the following code in the <body> section of an HTML file named, say, feedback.html.

<form method="post" action="sendmail.php">
  Email: <input name="email" type="text" />

  Message:

  <textarea name="message" rows="15" cols="40">
  </textarea>

  <input type="submit" />
</form>

The Feedback Form PHP Script

Now all that remains is to code "sendmail.php". This is made extremely easy by the facilities available in PHP. Type the following code into a file named "sendmail.php". Do not put anything else into that file, ie, don't put in any other HTML tags or headers, etc.

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "yourname@example.com", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.example.com/thankyou.html" );
?>

Offline eatit007

  • PHP Workers
  • **
  • Posts: 17
  • Karma: +0/-0
Re: Email PHP script
« Reply #2 on: December 19, 2008, 01:03:56 AM »
i manipulated it according to my contact form.
Quote
<?php
  $yname = $_REQUEST['yname'] ;
  $email = $_REQUEST['email'] ;
  $tarea = $_REQUEST['tarea'] ;

  mail( "123@gmail.com", "Feedback Form

Results",
    $tarea, $yname, "From: $email" );
  header("Location:thanks.html");
?>

an used WAMP to run it. the contact page did call the php file and i was directed to thanx.html page.
but i didn't receive any mail on my mail above ie. 123@gmail.com .....?? why??? can u help me out here????
« Last Edit: December 19, 2008, 01:10:04 AM by eatit007 »

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: Email PHP script
« Reply #3 on: December 19, 2008, 03:06:15 AM »
Try using this code:

Code: [Select]
//send email
$to = "mail@domain.com";
$subject = "your subject";
$body = "your message to be sent";
$additionalheaders = "From: <mail@domain.com>\r\n";
$additionalheaders .= "Replt-To:mail@domain.com";
mail($to, $subject, $body, $additionalheaders);

this is what I used to send mail with php.

Are you sending mail on a live server or locally? have you got SMTP enabled?

Offline eatit007

  • PHP Workers
  • **
  • Posts: 17
  • Karma: +0/-0
Re: Email PHP script
« Reply #4 on: December 20, 2008, 10:46:03 AM »
i was using WAMP at that time...
.. i am going to try your code...but tomorrow,,.
cya man...thanx a ton

Offline eatit007

  • PHP Workers
  • **
  • Posts: 17
  • Karma: +0/-0
Re: Email PHP script
« Reply #5 on: December 22, 2008, 03:43:10 AM »
Code: [Select]
the thing is i need to take input in my php file from the form the user filled.
so i manipulated ur script...

<?php

$to 
"eatit007@gmail.com";
$subject $_REQUEST['topic'];
$email $_REQUEST['email'];
$body $_REQUEST['msg'];
$additionalheaders "From:$email\r\n";
mail($to$subject$email$body$additionalheaders);

?>

i know...it is hard for you...but seriously it's even hard for me..the first timer in php.
i need ur mail id..pm me..i am going to send u the whole site. along with the two php scripts i have written.
the one is above..for the contact page...
adn another one is for the register page...
after making these work..i only need to make a login script..but that cannot be ran until i get the register page data stored..only then the login will work...

take a little bit more pain for me....plzzzzzzzzz



Offline eatit007

  • PHP Workers
  • **
  • Posts: 17
  • Karma: +0/-0
Re: Email PHP script
« Reply #6 on: December 22, 2008, 04:22:07 AM »
wrote the login script too...all i need now is you to debug it the code for me..mate...upload the files...i have a very very slow connection.. :(

Offline Diload

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Re: Email PHP script
« Reply #7 on: April 11, 2009, 08:30:44 AM »
do you have a smtp server running or do u got 1 you can use ?  and do you got php errors set so they are shown? ,,