Email Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xeonman13
Forum Newbie
Posts: 1
Joined: Thu Jan 19, 2006 3:28 pm

Email Script

Post by xeonman13 »

Hello All,
Im new here. ANd Im very happy I found this forum.
Hopefully you can help me.

I have a script that sends an email, its a trouble ticket system and it sends me an email when a new ticket is created.

The problem im having is that constantly, i get blank emails from the script, which means someone is just running the .php page that sends the email without the form prior to it. or maybe a crawler or something?

Is there something I can put on the page that sends the email that will not allow it to process unless there is information? or at least to validate that the only way it will continue is if it was redirected from the form page?

Any ideas?

Here is the page that sends the email.

Code: Select all

<?php
$to = "emailaddress"\r\n";
$re = "Ticket Updated by Customer # $ticketid";

$From = "From: techsupport@techsupport.com\r\n";
$body = <<< emailbody

Dear Technician.

An update has been posted to a ticket, # $ticketid
The customer wrote
$comment

If this update requires a response from you, please go to the support site and reply.
----------------------------------------------------
Sincerely,
Tech Support




emailbody;
$success = mail($to,$re,$body,$From);
	
?>
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

And how does the code with the form look like? How and were does the data come from?

Normally receiving data goes like:

Code: Select all

<?php
if (isset($_POST['submit'])
{


// process data ....


}
else
{
?>
html for form
<?php
}
?>
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Place a unique identifier (token) in a hidden field in the form. Place the same token in their browser. When the page loads do a comparison if the cookies are the same then show the form, if not send them to a different page. If they complete the form correctly, clear the one time cookie some time after the mail is sent? Sound good? The only thing better than that that I am aware of is a confirmation code that the end user enters.
Post Reply