Jump to content

Urgent code help needed - auto email not working


PorkPie

Recommended Posts

Hi ppl. I have some php from a booking sheet of mine. I am trying to send an automatic email with an e-voucher number to the customer. I'm still learning php coding, so I'm pretty rubbish still. Can someone help me find a solution to this part of the code: // Send e-voucher email to customer (near the bottom):

 

 

snip>>>>>

 

<? ob_start();

error_reporting("null");

session_start();

include("includes/config.php");

$userdet=array();

 

//insert the table

 

if(empty($_SESSION['bookingid']))

{

$userdet['detid']='';

$userdet['contname'] = $_REQUEST['contname'];

$userdet['contmidname '] = $_REQUEST['contmidname'];

$userdet['contsurname'] = $_REQUEST['contsurname'];

$userdet['contaddr'] = $_REQUEST['contaddr'];

$userdet['contcity'] = $_REQUEST['contcity'];

$userdet['contpostcode'] = $_REQUEST['contpostcode'];

$userdet['realship'] = $_REQUEST['relation'];

$userdet['contemail'] = $_REQUEST['contemail'];

$userdet['contnumber'] = $_REQUEST['contnumber'];

$userdet['bdefname'] = $_REQUEST['bdefirstname'];

$userdet['bdemldename'] =$_REQUEST['bdemiddlename'];

$userdet['bdesurname'] = $_REQUEST['bdesurname'];

$userdet['bdeaddr'] = $_REQUEST['bdeaddr'];

$userdet['bdecity'] = $_REQUEST['bdecity'];

$userdet['bdepostcode'] = $_REQUEST['bdepostcode'];

$userdet['grmfname'] = $_REQUEST['grmfirstname'];

$userdet['grmmldename'] = $_REQUEST['grmmiddlename'];

$userdet['grmsurname'] = $_REQUEST['grmsurname'];

$userdet['grmaddr'] = $_REQUEST['grmaddr'];

$userdet['grmcity'] = $_REQUEST['grmcity'];

$userdet['grmpostcode'] = $_REQUEST['grmpostcode'];

$userdet['bdrpartname'] = $_REQUEST['bdeparent'];

$userdet['grmpartname'] = $_REQUEST['grmparent'];

$userdet['bestmanname'] = $_REQUEST['bestmanname'];

$userdet['bridesmaid'] = $_REQUEST['bridename'];

$res=db_insert('tbluserdetails',$userdet);

if($res)

{

$rest=db_getRs('tbluserdetails','contemail="'.$_REQUEST['contemail'].'" and weddate="0000-00-00"');

$sql2=mysql_fetch_array($rest);

$bookingid=$sql2[0];

session_register("bookingid");

}

}

 

 

 

//update the table

if($_SESSION['bookingid'])

{

$userdet1=array();

$userdet1['contname'] = $_REQUEST['contname'];

$userdet1['contaddr'] = $_REQUEST['contaddr'];

$userdet1['contcity'] = $_REQUEST['contcity'];

$userdet1['contpostcode'] = $_REQUEST['contpostcode'];

$userdet1['realship'] = $_REQUEST['relation'];

$userdet1['contemail'] = $_REQUEST['contemail'];

$userdet1['contnumber'] = $_REQUEST['contnumber'];

$userdet1['bdefname'] = $_REQUEST['bdefirstname'];

$userdet1['bdemldename'] =$_REQUEST['bdemiddlename'];

$userdet1['bdesurname'] = $_REQUEST['bdesurname'];

$userdet1['bdeaddr'] = $_REQUEST['bdeaddr'];

$userdet1['bdecity'] = $_REQUEST['bdecity'];

$userdet1['bdepostcode'] = $_REQUEST['bdepostcode'];

$userdet1['grmfname'] = $_REQUEST['grmfirstname'];

$userdet1['grmmldename'] = $_REQUEST['grmmiddlename'];

$userdet1['grmsurname'] = $_REQUEST['grmsurname'];

$userdet1['grmaddr'] = $_REQUEST['grmaddr'];

$userdet1['grmcity'] = $_REQUEST['grmcity'];

$userdet1['grmpostcode'] = $_REQUEST['grmpostcode'];

$userdet1['bdrpartname'] = $_REQUEST['bdeparent'];

$userdet1['grmpartname'] = $_REQUEST['grmparent'];

$userdet1['bestmanname'] = $_REQUEST['bestmanname'];

$userdet1['bridesmaid'] = $_REQUEST['bridename'];

$res=db_update('tbluserdetails',$userdet1,'detid="'.$_SESSION['bookingid'].'"');

}

$res2=db_getRs('tbluserdetails','detid="'.$_SESSION['bookingid'].'"');

$sql=mysql_fetch_array($res2);

$wtime=explode(":", $sql['wedtime']);

$wmin=explode(" ",$wtime[1]);

$cdate=$_REQUEST['cdate'];

$cutdate=explode("-",$sql['weddate']);

 

 

//calculate the date

if($_REQUEST['cdate'])

{

$cutdate=explode("-", $_REQUEST['cdate']);

}

$year=$cutdate[0];

$mon=$cutdate[1];

$day=$cutdate[2];

 

switch ($mon)

{

  case 1: $mon="Jan"; break;

  case 2: $mon="Feb"; break;

  case 3: $mon="Mar"; break;

  case 4: $mon="Apr"; break;

  case 5: $mon="May"; break;

  case 6: $mon="Jun"; break;

  case 7: $mon="Jul"; break;

  case 8: $mon="Aug"; break;

  case 9: $mon="Sep"; break;

  case 10: $mon="Oct"; break;

  case 11: $mon="Nov"; break;

  case 12: $mon="Dec"; break;

}

 

 

// Send e-voucher email to customer

 

ob_start();

require("phpmailer/class.phpmailer.php");

include("includes/config.php");

$mail = new PHPMailer();

$mail->IsSMTP();                // send via SMTP

$mail->Host    = "localhost"; // SMTP servers

$mail->SMTPAuth = true;      // turn on SMTP authentication

$mail->Username = "";      // SMTP username

$mail->Password = "";

 

/*if($_REQUEST['weddingdet'])

{

$res=db_getRs('tbluserdetails','contemail="'.$_REQUEST['contemail'].'"');

$aff=mysql_affected_rows();

if($aff)

{

$sql=mysql_fetch_array($res);*/

 

if($_SESSION['bookingid'])

{

$userdet1=array();

$userdet1['contname'] = $_REQUEST['contname'];

$userdet1['contemail'] = $_REQUEST['contemail'];

$subject="E-voucher details from the company";

$message="Dear $contname <br>

            Your e-voucher is: 45345345<br>

".

;

 

    $headers  = 'MIME-Version: 1.0' . "\r\n";

    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $headers .= 'From: Support <support@mycompany.com>' . "\r\n";

        $mail->From    = "support@mycompany.com";

$mail->FromName = "mycompany.com";

$mail->AddAddress($to);

$mail->WordWrap = 50;                              // set word wrap

$mail->AddAttachment("/var/tmp/file.tar.gz");      // attachment

$mail->AddAttachment("/tmp/image.jpg", "new.jpg");

$mail->IsHTML(true);               

$mail->Subject  =  $subject;

$mail->Body    =  $message;

$mail->AltBody  =  $message;

        $a=mail($to, $subject, $message, $headers);

if(!$a)

{

$message1="Mail was not sent. Please Check Mail Address";

echo $message1;

}

else

{

header("location:thank_you.php");

}

}

else

{

$msg="Email address not found<br> Enter email address for your e-voucher";

}

}

 

 

?>

 

 

 

<<<<<

 

Thanks guys.

;D

Link to comment
Share on other sites

you could tell us what errors you are getting (if any) or what the result of the script is (like is any email sent at all or email sent but no attachement - that kind of thing really helps.

 

Otherwise we have to trawl through you code which we can't be bothered to do most of the time...

Link to comment
Share on other sites

This is where it is wrong...

 

 

>>>>>

 

// Send e-voucher email to customer

 

ob_start();

require("phpmailer/class.phpmailer.php");

include("includes/config.php");

$mail = new PHPMailer();

$mail->IsSMTP();                // send via SMTP

$mail->Host    = "localhost"; // SMTP servers

$mail->SMTPAuth = true;      // turn on SMTP authentication

$mail->Username = "";      // SMTP username

$mail->Password = "";

 

/*if($_REQUEST['weddingdet'])

{

$res=db_getRs('tbluserdetails','contemail="'.$_REQUEST['contemail'].'"');

$aff=mysql_affected_rows();

if($aff)

{

$sql=mysql_fetch_array($res);*/

 

if($_SESSION['bookingid'])

{

$userdet1=array();

$userdet1['contname'] = $_REQUEST['contname'];

$userdet1['contemail'] = $_REQUEST['contemail'];

$subject="E-voucher details from the company";

$message="Dear $contname

 

            Your e-voucher is: 45345345

 

          ".

        ;

 

    $headers  = 'MIME-Version: 1.0' . "\r\n";

    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $headers .= 'From: Support <support@mycompany.com>' . "\r\n";

        $mail->From    = "support@mycompany.com";

      $mail->FromName = "mycompany.com";

      $mail->AddAddress($to);

      $mail->WordWrap = 50;                              // set word wrap

      $mail->AddAttachment("/var/tmp/file.tar.gz");      // attachment

      $mail->AddAttachment("/tmp/image.jpg", "new.jpg");

      $mail->IsHTML(true);               

      $mail->Subject  =  $subject;

      $mail->Body    =  $message;

      $mail->AltBody  =  $message;

        $a=mail($to, $subject, $message, $headers);

      if(!$a)

      {

      $message1="Mail was not sent. Please Check Mail Address";

      echo $message1;

      }

      else

      {

      header("location:thank_you.php");

      }

}

else

{

$msg="Email address not found

Enter email address for your e-voucher";

}

}

 

<<<<<<<

Link to comment
Share on other sites

1. does it email (check junk/spam)

2. any errors (did you comment out the ob_start()'s

3. are your email server details correct ?

4. try echoing some date ie

$_REQUEST['contemail']

$aff

$_SESSION['bookingid']

 

we need details worst case add die("TEST"); at the start then test you get t he message TEST, move it down until you stop getting it, the line before is probably the problem!

Link to comment
Share on other sites

Sure....

 

1. The code was all working before I added the // Send e-voucher email to customer

2. I wanted to use the $_REQUEST['contemail']; to auto email the customer an email when he/she submitted this part of this booking form (there are several parts)

3. Now all I get is a blank page. Granted there is a page before this that puts things into variables/arrays but I tried completing that too but still get a blank on this page.

4. I assume the code that I have for auto emailing is wrong.

 

I can see no errors, just a blank page.

 

Can I simplify this auto email code some way?

 

 

Link to comment
Share on other sites

I removed the whole section of this and the page came back.

 

>>>>>>

 

// Send e-voucher email to customer

 

ob_start();

require("phpmailer/class.phpmailer.php");

include("includes/config.php");

$mail = new PHPMailer();

$mail->IsSMTP();                // send via SMTP

$mail->Host    = "localhost"; // SMTP servers

$mail->SMTPAuth = true;      // turn on SMTP authentication

$mail->Username = "";      // SMTP username

$mail->Password = "";

 

/*if($_REQUEST['weddingdet'])

{

$res=db_getRs('tbluserdetails','contemail="'.$_REQUEST['contemail'].'"');

$aff=mysql_affected_rows();

if($aff)

{

$sql=mysql_fetch_array($res);*/

 

$message = " $todayis [EST] \n

Attention: $attn \n

From: $name ($visitormail)\n

Senders Message: $notes \n

Introducing: \n

Couples Name: $coupleintroname \n

Couples Email: $coupleintromail \n

Couples Address: $coupleintroaddr \n

Couples Telephone: $coupleintrotel \n

 

Additional Info : IP = $ip \n

Browser Info: $httpagent \n

Referral : $httpref \n

 

";

 

$from = "From: $visitormail\r\n";

 

 

mail("****", $subject, $message, $from);

 

 

 

if($_SESSION['bookingid'])

{

$userdet1=array();

$userdet1['contname'] = $_REQUEST['contname'];

$userdet1['contemail'] = $_REQUEST['contemail'];

$subject="E-voucher details from the company";

$message="Dear $contname <br>

            Your e-voucher is: 45345345<br>

".

;

 

    $headers  = 'MIME-Version: 1.0' . "\r\n";

    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $headers .= 'From: Login Details<support@mycompany.com>' . "\r\n";

        $mail->From    = "support@mycompany.com";

$mail->FromName = "mycompany.com";

$mail->AddAddress($to);

$mail->WordWrap = 50;                              // set word wrap

$mail->AddAttachment("/var/tmp/file.tar.gz");      // attachment

$mail->AddAttachment("/tmp/image.jpg", "new.jpg");

$mail->IsHTML(true);               

$mail->Subject  =  $subject;

$mail->Body    =  $message;

$mail->AltBody  =  $message;

        $a=mail($to, $subject, $message, $headers);

if(!$a)

{

$message1="Mail does not sent. Please Check Mail Id";

echo $message1;

}

else

{

header("location:thank_you.php?forgetpass=1");

}

}

else

{

$msg="User Name not found <br> Enter Correct User Name";

}

 

 

<<<<<

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.