Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Sending a auto reply to sender from PHP form

General discussions related to php

Moderators: macek, egami, gesf

Sending a auto reply to sender from PHP form

Postby popcop » Mon Jul 23, 2012 1:43 am

Im using the below code to submit form information to my email account but i also want it to send a confirmation email to the sender but its not working... can you see anything from the code that might be stopping this from sending??

Code: Select all
 <?
ob_start();
if(isset($_POST['btnSubmit']))
{
require("class.phpmailer.php");

$mail = new PHPMailer();

//Your SMTP servers details

$mail->IsSMTP();               // set mailer to use SMTP
$mail->Host = "localhost";  // specify main and backup server or localhost
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "hello@frogdigital.co.uk";  // SMTP username
$mail->Password = "*****"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

$mail->From = $mail->hello;    //Default From email same as smtp user
$mail->FromName = $_POST['fullname'];

$mail->AddAddress("hello@frogdigital.co.uk", "Frog Digital"); //Email address where you wish to receive/collect those emails.

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = $_POST['service'];

$message = "<b>Name: </b>".$_POST['fullname']." \r\n <br><br><b>Email: </b>".$_POST['email']." \r\n <br><br><b>Service: </b>".$_POST['service']." \r\n <br><br><b>Budget: </b>".$_POST['budget']." \r\n <br><br><b>Comments: </b>".$_POST['comments'];
$mail->Body    = $message;


if ($mail->send()){
  $autoemail = new PHPMailer();
  $autoemail->From = "hello@frogdigital.co.uk";
  $autoemail->FromName = "Frog Digital";
  $autoemail->AddAddress($mail->From, $mail->FromName);
  $autoemail->Subject = "Autorepsonse: We received your submission";
  $autoemail->Body = "We received your submission. We will contact you soon ...";
}




?>
popcop
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jul 23, 2012 1:39 am

Re: Sending a auto reply to sender from PHP form

Postby Odie2828 » Mon Jul 23, 2012 3:17 am

I dont see the server details for the new $autoemail instance:

Code: Select all
$autoemail->IsSMTP();               // set mailer to use SMTP
$autoemail->Host = "localhost";  // specify main and backup server or localhost
$autoemail->SMTPAuth = true;     // turn on SMTP authentication
$autoemail->Username = "hello@frogdigital.co.uk";  // SMTP username
$autoemail->Password = "*****"; // SMTP password


Also there is no closing } for your initial if(isset($_POST['btnSubmit'])){

It would go at the bottom before ?>
Odie2828
New php-forum User
New php-forum User
 
Posts: 19
Joined: Mon Jul 23, 2012 3:14 am

Re: Sending a auto reply to sender from PHP form

Postby popcop » Mon Jul 23, 2012 3:31 am

adding this code helps send the form information to my email but the confirmation email is still not being sent back to the user :(

any other ideas?
popcop
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jul 23, 2012 1:39 am

Re: Sending a auto reply to sender from PHP form

Postby Odie2828 » Mon Jul 23, 2012 3:41 am

You code looks like this now?

Code: Select all
ob_start();
if(isset($_POST['btnSubmit']))
{
   require("class.phpmailer.php");
   
   $mail = new PHPMailer();
   
   //Your SMTP servers details
   
   $mail->IsSMTP();               // set mailer to use SMTP
   $mail->Host = "localhost";  // specify main and backup server or localhost
   $mail->SMTPAuth = true;     // turn on SMTP authentication
   $mail->Username = "hello@frogdigital.co.uk";  // SMTP username
   $mail->Password = "*****"; // SMTP password
   //It should be same as that of the SMTP user
   
   $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
   
   $mail->From = $mail->hello;    //Default From email same as smtp user
   $mail->FromName = $_POST['fullname'];
   
   $mail->AddAddress("hello@frogdigital.co.uk", "Frog Digital"); //Email address where you wish to receive/collect those emails.
   
   $mail->WordWrap = 50;                                 // set word wrap to 50 characters
   $mail->IsHTML(true);                                  // set email format to HTML
   
   $mail->Subject = $_POST['service'];
   
   $message = "<b>Name: </b>".$_POST['fullname']." \r\n <br><br><b>Email: </b>".$_POST['email']." \r\n <br><br><b>Service: </b>".$_POST['service']." \r\n <br><br><b>Budget: </b>".$_POST['budget']." \r\n <br><br><b>Comments: </b>".$_POST['comments'];
   $mail->Body    = $message;
   
   
   if ($mail->send()){
      $autoemail = new PHPMailer();
      $autoemail->IsSMTP();               // set mailer to use SMTP
      $autoemail->Host = "localhost";  // specify main and backup server or localhost
      $autoemail->SMTPAuth = true;     // turn on SMTP authentication
      $autoemail->Username = "hello@frogdigital.co.uk";  // SMTP username
      $autoemail->Password = "*****"; // SMTP password
      $autoemail->From = "hello@frogdigital.co.uk";
      $autoemail->FromName = "Frog Digital";
      $autoemail->AddAddress($mail->From, $mail->FromName);
      $autoemail->Subject = "Autorepsonse: We received your submission";
      $autoemail->Body = "We received your submission. We will contact you soon ...";
   }
}


Also, how is $mail->hello getting the email address to set as $mail->From?

$mail->From = "the user who filled out the form email address"; //$_POST['email']; or something
and then the AddAddress line should be AddAddress("user email", "from name");
Odie2828
New php-forum User
New php-forum User
 
Posts: 19
Joined: Mon Jul 23, 2012 3:14 am

Re: Sending a auto reply to sender from PHP form

Postby popcop » Mon Jul 23, 2012 3:48 am

yeah exactly like that...

the form information is being sent but still no confirmation email

the page isnt being redirected back to the home page after submission either now.... im guessing thats because of the confirmation email not being sent
popcop
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jul 23, 2012 1:39 am

Re: Sending a auto reply to sender from PHP form

Postby Odie2828 » Mon Jul 23, 2012 3:50 am

Can you send me the whole code to your file...
Odie2828
New php-forum User
New php-forum User
 
Posts: 19
Joined: Mon Jul 23, 2012 3:14 am

Re: Sending a auto reply to sender from PHP form

Postby Odie2828 » Mon Jul 23, 2012 4:20 am

im sorry, i must be more tired than i thought.

Your new phpmailer doesnt have a $autoemail->send(); in there....

This is what i did to test it:
Code: Select all
$email = 'my email';
$fromname = 'JD Vangsness';
$fullname = 'JD Vangsness';
$service = 'test Service 2';
$budget = '20 bucks';
$comments = 'i like';

$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP();               // set mailer to use SMTP
$mail->Host = "localhost";  // specify main and backup server or localhost
$mail->SMTPAuth = false;     // turn on SMTP authentication
//$mail->Username = "hello@frogdigital.co.uk";  // SMTP username
//$mail->Password = "*****"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
$mail->From = $email;    //Default From email same as smtp user
$mail->FromName = $fullname;
$mail->AddAddress("my email", "Frog Digital"); //Email address where you wish to receive/collect those emails.
$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML
$mail->Subject = $service;
$message = "<b>Name: </b>".$fullname." \r\n <br><br><b>Email: </b>".$email." \r\n <br><br><b>Service: </b>".$service." \r\n <br><br><b>Budget: </b>".$budget." \r\n <br><br><b>Comments: </b>".$comments;
$mail->Body    = $message;


if($mail->send()){

   $autoemail = new PHPMailer(true);
   $autoemail->IsSMTP();               // set mailer to use SMTP
   $autoemail->Host = "localhost";  // specify main and backup server or localhost
   $autoemail->SMTPAuth = false;     // turn on SMTP authentication
   //$autoemail->Username = "hello@frogdigital.co.uk";  // SMTP username
   //$autoemail->Password = "*****"; // SMTP password
   $autoemail->From = "jd@jdvinnovations.com";
   $autoemail->FromName = "Frog Digital";
   $autoemail->AddAddress($email, $fullname);
   $autoemail->Subject = "Autorepsonse: We received your submission";
   $autoemail->Body = "We received your submission. We will contact you soon ...";
   $autoemail->send();
}
Odie2828
New php-forum User
New php-forum User
 
Posts: 19
Joined: Mon Jul 23, 2012 3:14 am

Re: Sending a auto reply to sender from PHP form

Postby popcop » Mon Jul 23, 2012 4:48 am

nothing being sent at all now...

i don know if this is causing the problem but my hosting company have blocked the use of the mail function on their servers... they advised me to do it this way so itll work ??


heres the code

Code: Select all
<?
ob_start();
if(isset($_POST['btnSubmit']))
{
require("class.phpmailer.php");

$mail = new PHPMailer();

//Your SMTP servers details

$mail->IsSMTP();               // set mailer to use SMTP
$mail->Host = "localhost";  // specify main and backup server or localhost
$mail->SMTPAuth = false;     // turn on SMTP authentication
$mail->Username = "hello@frogdigital.co.uk";  // SMTP username
$mail->Password = "*****"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

$mail->From = $email;    //Default From email same as smtp user
$mail->FromName = $fullname;

$mail->AddAddress("my email", "Frog Digital"); //Email address where you wish to receive/collect those emails.

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = $service;

$message = "<b>Name: </b>".$fullname." \r\n <br><br><b>Email: </b>".$email." \r\n <br><br><b>Service: </b>".$service." \r\n <br><br><b>Budget: </b>".$budget." \r\n <br><br><b>Comments: </b>".$comments;
$mail->Body    = $message;


if($mail->send()){

   $autoemail = new PHPMailer(true);
   $autoemail->IsSMTP();               // set mailer to use SMTP
   $autoemail->Host = "localhost";  // specify main and backup server or localhost
   $autoemail->SMTPAuth = false;     // turn on SMTP authentication
   $autoemail->Username = "hello@frogdigital.co.uk";  // SMTP username
   $autoemail->Password = "*****"; // SMTP password
   $autoemail->From = "hello@frogdigital.co.uk";
   $autoemail->FromName = "Frog Digital";
   $autoemail->AddAddress($email, $fullname);
   $autoemail->Subject = "Autorepsonse: We received your submission";
   $autoemail->Body = "We received your submission. We will contact you soon ...";
   $autoemail->send();
}


?>
popcop
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jul 23, 2012 1:39 am

Re: Sending a auto reply to sender from PHP form

Postby Odie2828 » Mon Jul 23, 2012 5:02 am

Here you go, i have cleaned it up a little bit.
Please make sure to check the $_POST variables at the top so they match your form. Also put your SMTP_PASS in..

Code: Select all
<?
ob_start();
if(isset($_POST['btnSubmit'])){
   
   // Require the phpMailer Class
   require("class.phpmailer.php");
   
   // Set the variables from the form
   $service = $_POST['service'];
   $email = $_POST['email'];
   $budget = $_POST['budget'];
   $comments = $_POST['commnets'];
   $fullname = $_POST['fullname'];
   
   // Set my information
   $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
   $to_email = "hello@frogdigital.co.uk";
   $SMTP_HOST = "localhost";
   $SMTP_USER = "hello@frogdigital.co.uk";
   $SMTP_PASS = ""; // <-----------------------<----------------your password here
      
   // Start the mailer
   $mail = new PHPMailer();
   $mail->IsSMTP();               // set mailer to use SMTP
   $mail->Host = $SMTP_HOST;  // specify main and backup server or localhost
   $mail->SMTPAuth = false;     // turn on SMTP authentication
   $mail->Username = $SMTP_USER;  // SMTP username
   $mail->Password = $SMTP_PASS; // SMTP password
   $mail->From = $email;    //Default From email same as smtp user
   $mail->FromName = $fullname;
   $mail->AddAddress($to_email, "Frog Digital"); //Email address where you wish to receive/collect those emails.
   $mail->WordWrap = 50;                                 // set word wrap to 50 characters
   $mail->IsHTML(true);                                  // set email format to HTML
   $mail->Subject = $service;
   $message = "<b>Name: </b>".$fullname." \r\n <br><br><b>Email: </b>".$email." \r\n <br><br><b>Service: </b>".$service." \r\n <br><br><b>Budget: </b>".$budget." \r\n <br><br><b>Comments: </b>".$comments;
   $mail->Body    = $message;
      
   if($mail->send()){
   
      $autoemail = new PHPMailer(true);
      $autoemail->IsSMTP();               // set mailer to use SMTP
      $autoemail->Host = "localhost";  // specify main and backup server or localhost
      $autoemail->SMTPAuth = false;     // turn on SMTP authentication
      $autoemail->Username = "hello@frogdigital.co.uk";  // SMTP username
      $autoemail->Password = "*****"; // SMTP password
      $autoemail->From = $to_email;
      $autoemail->FromName = "Frog Digital";
      $autoemail->AddAddress($email, $fullname);
      $autoemail->Subject = "Autorepsonse: We received your submission";
      $autoemail->Body = "We received your submission. We will contact you soon ...";
      
      if($autoemail->send()){
         header('Location: '.$redirect_url);
      }
   
   }

}
?>


Let me know....
Odie2828
New php-forum User
New php-forum User
 
Posts: 19
Joined: Mon Jul 23, 2012 3:14 am

Re: Sending a auto reply to sender from PHP form

Postby popcop » Mon Jul 23, 2012 5:19 am

EDIT.... working now! :)
popcop
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jul 23, 2012 1:39 am

Re: Sending a auto reply to sender from PHP form

Postby Odie2828 » Mon Jul 23, 2012 5:45 am

Ok great!
Odie2828
New php-forum User
New php-forum User
 
Posts: 19
Joined: Mon Jul 23, 2012 3:14 am


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron