SkyRanger Posted April 16, 2007 Share Posted April 16, 2007 I am having a problem auto sending a email on reply. Not sure what the problem is, can anybody help? if ($submit) { //define the receiver of the email $to = '$semail'; //define the subject of the email $subject = 'Support - Ticket Number: $ticketno'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: $suemail\r\nReply-To: $suemail"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit ====================================================== Ticket Number: <?php echo $ticketno; ?> Date of request: <?php echo $sdate; ?> Subject: <?php echo $ssubject; ?> Description: <?php echo $formmessage; ?> To reply to this message, or send another ticket click below: http://<?php echo $dbdomain; ?> Please do not reply to this message. ====================================================== From: <?php echo $dbemail; ?> --PHP-alt-<?php echo $random_hash; ?>-- <? //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); $connectionu=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbname"); mysql_db_query("$dbname", "UPDATE support SET status = 'completed', admin = '$adminname' WHERE ticketno = '$ticketno'") or die('I cannot update the database because: ' . mysql_error()); $sql = "INSERT INTO support_replies (ticketno,description,date,user) VALUES ('$ticketno','$formmessage','time()','$adminname')"; $result = mysql_query($sql) or die ('I could not add information to the database because ' . mysql_error()); mysql_close($connectionu); echo "<b>Your request has been sent.</b><br>Please click here to return to the $dbcompany Manager Index:<br><a href=index2.php>$dbcompanyManager Index</a>; } else{ ...form here... All the information is echoed to the submit but the email is not going out Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/ Share on other sites More sharing options...
bsprogs Posted April 16, 2007 Share Posted April 16, 2007 On the line where you actually send the email, take off the @ and see if it gives you a warning which may be keeping the email from being sent. <?php $mail_sent = mail( $to, $subject, $message, $headers ); ?> You could also echo the result of $mail_sent after the email should have been sent to see what it tells you. Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230101 Share on other sites More sharing options...
SkyRanger Posted April 16, 2007 Author Share Posted April 16, 2007 No, still not working, thinking about starting from scratch. It may be a problem with the insert and update mysql lines messing with the mail part. Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230121 Share on other sites More sharing options...
bsprogs Posted April 16, 2007 Share Posted April 16, 2007 What does it show if you echo the result of $mail_sent? Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230122 Share on other sites More sharing options...
SkyRanger Posted April 16, 2007 Author Share Posted April 16, 2007 For some reason, all it echoed was a 1 and that is it...lol. Scratching my head and searching the script to find out where the 1 came from. Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230130 Share on other sites More sharing options...
marcus Posted April 16, 2007 Share Posted April 16, 2007 You don't echo the result of a mail function. Do: if($mail_sent = mail( $to, $subject, $message, $headers )){ echo "Mail sent"; }else { echo "Error sending mail"; } Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230134 Share on other sites More sharing options...
bsprogs Posted April 16, 2007 Share Posted April 16, 2007 from PHP.net Description bool mail ( string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] ) Sends an email. I believe that bool means it will return a 1 if is it executed successfully and a 0 if it fails. Looking at your code again, I see this line //define the receiver of the email $to = '$semail'; What does $semail actually equal in the above code? Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230137 Share on other sites More sharing options...
marcus Posted April 16, 2007 Share Posted April 16, 2007 If a variable is defined again in single quotes it will be as written as the variable name, not the definition of the variable. $email = "admin@neoblob.com"; echo '$email'; //this would produce $email, instead of admin@neoblob.com //in your case $to actually is defined as $semail, not the email you specified Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230141 Share on other sites More sharing options...
bsprogs Posted April 16, 2007 Share Posted April 16, 2007 If a variable is defined again in single quotes it will be as written as the variable name, not the definition of the variable. $email = "admin@neoblob.com"; echo '$email'; //this would produce $email, instead of admin@neoblob.com Wow, I completely overlooked that! Skyranger, try replacing the ' with " around the variables //define the receiver of the email $to = "$semail"; //define the subject of the email $subject = "Support - Ticket Number: $ticketno"; Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230143 Share on other sites More sharing options...
SkyRanger Posted April 16, 2007 Author Share Posted April 16, 2007 Doh, ok, so far I can get it to send if i use the $to = "manuallyputinemail"; now I have to figure out why the $semail is not inserting, stupid "" can get you into alot of trouble...lol Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230153 Share on other sites More sharing options...
bsprogs Posted April 16, 2007 Share Posted April 16, 2007 lol Where does the variable $semail get it's value from? Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230155 Share on other sites More sharing options...
SkyRanger Posted April 16, 2007 Author Share Posted April 16, 2007 This is where $semail is coming from $querypl = mysql_db_query("$dbname", "SELECT * FROM support WHERE ticketno = '$ticketno'") or die("Unable to select Database"); $rowpl = mysql_num_rows($querypl); while ($rowpl = mysql_fetch_array($querypl)) { $sticketno = $rowpl["ticketno"]; $susername = $rowpl["username"]; $semail = $rowpl["email"]; more ..... <form method="post" action=<?PHP echo $PHP_SELF?>> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber10" height="8" valign="top"> <tr> <td width="84%" align="center" height="5" valign="top" colspan="2" bgcolor="#558FA2"> <p align="left"><font color="#FFFFFF"><b>Ticket Number: <?php echo $ticketno; ?></b></font></td> </tr> <input type="hidden" name="ticketno" value=<?php echo $ticketno ?>> <tr> <td width="21%" align="right" height="7" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">User:</td> <td width="63%" align="left" height="7" valign="top"> <p style="margin-left: 5"><?php echo $susername ?></td> </tr> <tr> <td width="21%" align="right" height="5" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">Email:</td> <td width="63%" align="left" height="5" valign="top"> <p style="margin-left: 5"><?php echo $semail ?></td> <---- comes from here </tr> <tr> <td width="21%" align="right" height="6" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">Domain:</td> <td width="63%" align="left" height="6" valign="top"> <p style="margin-left: 5"><a href=http://<?php echo $sdomain ?> target="new"><?php echo $sdomain ?></a></td> </tr> <tr> <td width="21%" align="right" height="7" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">Date:</td> <td width="63%" align="left" height="7" valign="top"> <p style="margin-left: 5"><?php echo $sdate ?></td> </tr> <tr> <td width="21%" align="right" height="5" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">Subject:</td> <td width="63%" align="left" height="5" valign="top"> <p style="margin-left: 5"><?php echo $ssubject ?></td> </tr> <tr> <td width="21%" align="right" height="7" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">Original Question:</td> <td width="63%" align="left" height="7" valign="top" bgcolor="#66CCFF"> <p style="margin-left: 5"><?php echo nl2br("$smessage"); ?></td> </tr> <?php $querysr = mysql_db_query("$dbname", "SELECT * FROM `support_replies` WHERE ticketno = '$ticketno'") or die("Unable to select Database"); $rowsr = mysql_num_rows($querysr); while ($rowsr = mysql_fetch_array($querysr)) { $srticketno = $rowsr["ticketno"]; $srmessage = $rowsr["description"]; $srdate = $rowsr["date"]; $sruser = $rowsr["user"]; if($rownumber == "0"){ echo nl2br(" <tr> <td width=\"21%\" align=\"right\" valign=\"top\" bgcolor=\"#EEEEF8\"><p style=\"margin-right: 5\"><font color=\"#000000\">$sruser:</font></td> <td width=\"63%\" align=\"left\" valign=\"top\" bgcolor=\"#EEEEF8\"><p style=\"margin-left: 5\"><font color=\"#000000\">$srmessage</font></td> </tr>"); $rownumber = "1"; }else { echo nl2br("<tr> <td width=\"21%\" align=\"right\" valign=\"top\" bgcolor=\"#FBF7D7\"><p style=\"margin-right: 5\"><font color=\"#000000\">$sruser:</font></td> <td width=\"63%\" align=\"left\" valign=\"top\" bgcolor=\"#FBF7D7\"><p style=\"margin-left: 5\"><font color=\"#000000\">$srmessage</font></td> </tr>"); $rownumber = "0"; } } ?> <tr> <td width="21%" align="right" height="6" valign="top" bgcolor="#C0C0C0"> <p style="margin-right: 5">Add to Call:</td> <td width="63%" align="left" height="6" valign="top"> <p><textarea name="formmessage" cols="35" rows="6" wrap="true"></textarea></td> </tr> <tr> <td width="84%" align="right" height="7" valign="top" colspan="2"> </td> </tr> <tr> <td width="84%" align="right" height="8" valign="top" colspan="2"> <p align="center"><input type="Submit" name="submit" value="Send Reply"></form></td> </tr> <tr> <td width="84%" align="right" height="3" valign="top" colspan="2"> <p align="center"><a href=deletehd.php?ticketno=<?php echo $ticketno ?>>Delete Message</a> OR <a href=closehd.php?ticketno=<?php echo $ticketno ?>>Close Message</a> </td> </tr> <? } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230292 Share on other sites More sharing options...
SkyRanger Posted April 16, 2007 Author Share Posted April 16, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230368 Share on other sites More sharing options...
SkyRanger Posted April 16, 2007 Author Share Posted April 16, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230507 Share on other sites More sharing options...
bsprogs Posted April 16, 2007 Share Posted April 16, 2007 This doesn't make sense to me. $rowpl = mysql_num_rows($querypl); while ($rowpl = mysql_fetch_array($querypl)) { ... $rowpl is used as a variable for two completely different results. Anyways, instead of using: mysql_db_query(); try using mysql_select_db(); mysql_query(); It's recommended that you do this from php.net http://php.net/mysql_db_query ChangeLog Version - 4.0.6 Description This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead. It's worth a shot Quote Link to comment https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.