PDA

View Full Version : Update record form wizard modification


southafricadude
10-25-2012, 11:45 AM
Hi there,

I am not sure if this is the correct part of the forum to post this, sorry if its not.

I am wanting to update a record in a database, and am using the update record form wizard which works perfectly. My problem is that I would like the contents of the form to ALSO be sent in a PHP email to an email address once the form is updated, or before, it makes no difference.

How can I do this?

In the page with the form I have the code:

$updateGoTo = "thank-you.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}

//I added this:
//Email form:

$header = "from: $Name <$Email>". "\n";
$header .= "Reply-To: $Email". "\n";
$header .= "Return-Path: $Email". "\n";

$header .= 'MIME-Version: 1.0' . "\n";
$header .= "X-Priority: 3\n";
$header .= "X-Mailer: PHP". phpversion() ."\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\n";

$Name = $_REQUEST['Name'];
$Email = $_REQUEST['Email'];
$Telephone = $_REQUEST['Telephone'];
$country = $_REQUEST['country'];

$to ='xxxxx@domain.com';
$body = "
<html><body>
<table width=\"600\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >
<tr>
<td colspan=\"2\"><strong>enquiry from the website:</strong></td>
</tr>
<tr>
<td>Name:</td>
<td>".$Name."</td>
</tr>
<tr>
<td>Email:</td>
<td>$Email</td>
</tr>
<tr>
<td>Telephone:</td>
<td>$Telephone</td>
</tr>
<tr>
<td>Type of customer: </td>
<td>$country</td>
</tr>
</table>
</body></html>

";

$send_contact=mail($to,$subject,$body);

//End Email form


header(sprintf("Location: %s", $updateGoTo));
}

//End of my changes


This does not seem to work, the form still updates, but no email is sent.

Can anyone offer some advice?

Thanks!

student101
10-26-2012, 09:10 AM
Does your host support the mail function?
Do this tut (http://www.dreamweaverclub.com/dreamweaver-php-form.php)& see if it works then tell us.


Aah I see...

$updateGoTo = "thank-you.php";
if (isset($_SERVER['QUERY_STRING']))
{
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

$updateGoTo .= $_SERVER['QUERY_STRING'];
}

//I added
this:
//Email form:

$header = "from: $Name <$Email>".
"\n";
$header .= "Reply-To: $Email". "\n";
$header .= "Return-Path:
$Email". "\n";

$header .= 'MIME-Version: 1.0' . "\n";
$header .=
"X-Priority: 3\n";
$header .= "X-Mailer: PHP". phpversion() ."\n";

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

$Name = $_REQUEST['Name'];
$Email =
$_REQUEST['Email'];
$Telephone = $_REQUEST['Telephone'];
$country =
$_REQUEST['country'];

$to ='xxxxx@domain.com';
$body = "
<
html><body>
< table width=\"600\" border=\"0\" cellpadding=\"0\"
cellspacing=\"0\" >
<tr>
<td
colspan=\"2\"><strong>enquiry from the
website:</strong></td>
</tr>
<tr>

<td>Name:</td>
<td>".$Name."</td>

</tr>
<tr>
<td>Email:</td>

<td>$Email</td>
</tr>
<tr>

<td>Telephone:</td>
<td>$Telephone</td>

</tr>
<tr>
<td>Type of customer: </td>

<td>$country</td>
< /tr>
< /table>
<
/body></html>

";

$send_contact=mail($to,$subject,$body);

//add this
if ($send_conact) {
//usually your next command
}else{
// if it failed do or say something
}

//End
Email form


header(sprintf("Location: %s",
$updateGoTo));
}

//End of my changes

jmichae3
10-26-2012, 09:11 AM
change
$send_contact=mail($to,$subject,$body);
to
$send_contact=mail($to,$subject,$body,$header);

see http://us2.php.net/manual/en/function.mail.php
you have the headers all made, you just forgot to include them in your email. also, yahoo mail may be spam-filtering, so add this email address to your contacts.

student101
10-26-2012, 09:20 AM
I haven't tested your code but it suggests that you don't have to call the command $send_contact after declaring it?

southafricadude
10-26-2012, 09:31 AM
The server should send the mail fine as I am using a similar form for a regular feedback form and it mails perfectly.

I added the $header already yes, I forgot to update my post here. The form processes still, but no mail arrives.

Is there a way to display a message or something before completing the final step with the redirect to the thank-you page

header(sprintf("Location: %s", $updateGoTo));

Or some way for me to see if the form is indeed processing or giving an error or something. I have ssh access to the server, its on amazon cloud hosting.

I would have thought that if there was an issue, there would be an error message of sorts and the script would stop before processing the update.

I am sending the mail to the same gmail address I use elsewhere on the site in the contact form that uses an almost identical send mail script. I just checked that accounts spam folder too, and there is nothing there :(

Thanks so much for the advice so far! Any other suggestions?

student101
10-26-2012, 09:38 AM
Check Example #4 Sending HTML email (http://php.net/manual/en/function.mail.php#example-3191)

Test it.

jmichae3
10-26-2012, 10:35 AM
The server should send the mail fine as I am using a similar form for a regular feedback form and it mails perfectly.

I added the $header already yes, I forgot to update my post here. The form processes still, but no mail arrives.

Is there a way to display a message or something before completing the final step with the redirect to the thank-you page

header(sprintf("Location: %s", $updateGoTo));

Or some way for me to see if the form is indeed processing or giving an error or something. I have ssh access to the server, its on amazon cloud hosting.

I would have thought that if there was an issue, there would be an error message of sorts and the script would stop before processing the update.

I am sending the mail to the same gmail address I use elsewhere on the site in the contact form that uses an almost identical send mail script. I just checked that accounts spam folder too, and there is nothing there :(

Thanks so much for the advice so far! Any other suggestions?

another thing to check is if your php.ini is even configured for sending mail, and if so, what it's configured for.

for contact-me forms, I have had to use a dummy server email address as the from address and use the user's email address for the reply-to address. when YOU get the email, it will be from the server, but when you reply, it will switch automatically to sending to their address.

and you should have a reply address in your headers, or it won't send.

southafricadude
10-26-2012, 11:41 AM
Thanks for the help so far. I am making progress!

I changed the code to:

$send_contact=mail($to,$subject,$body,$header);

//End Email form
if($send_contact){
header(sprintf("Location: %s", $updateGoTo));
}
else {
echo "ERROR processing, please contact us directly at xxxxx@gmail.com";
}
}

Now when the form goes, it still makes the changes in the database, but I get the error message, so I know there is something wrong with the form code, and it is NOT sending, so I can rule out spam filters etc.

The error log in the server says: sendmail.ssmtp: 555 5.5.2 Syntax error. xq19sm542168veb.0

So at least now I know the problem has to do with the email script itself, if I get that fixed then in theory I should not get the error message, and the mail should send....I'll keep you posted.

jmichae3
10-29-2012, 12:52 AM
the syntax error is not necessarily an error inthe script but in the format/syntax of the email -(since it comes from the smtp server).

jmichae3
10-29-2012, 01:45 AM
oh, here is the problem,your html is borked.
< /tr>
< /table>
<
/body>
should be
</tr>
</table>
</body>

no spaces allowed before / in </sometagname>
also, no space allowed betweem < and sometagname in <sometagname> but you can have a space between <sometagname and > though or between <sometagname and />

so your <
html>
should be
<html>

it's just mangled html. probably why the smtp server didn't like it - you specified text/html for the format of your email.