Jump to content

[SOLVED] Email Problem


SkyRanger

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230101
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230137
Share on other sites

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 = "[email protected]";
echo '$email';
//this would produce $email, instead of [email protected]
//in your case $to actually is defined as $semail, not the email you specified

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230141
Share on other sites

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 = "[email protected]";
echo '$email';
//this would produce $email, instead of [email protected]

 

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";

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230143
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230292
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/47185-solved-email-problem/#findComment-230812
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.