PDA

View Full Version : Need some help.



ChrisWade
05-23-2007, 01:23 AM
I have a submit button that send the form to a 3rd party source, is there a way to add some code to it so that I can also have it sent to my own email. That way I dont have to constantly check the 3rd party site

or would it be easier to create my own form and send the info in an email that way.

djr33
05-23-2007, 02:12 AM
You can't send it two places. It just goes to the action of the form. That page could do multiple things with the data, but you can't have that actually be two pages at the same time.
You could write your own PHP script that would do both, though, if that sounds like a good option.

codeexploiter
05-23-2007, 03:23 AM
What about trying Ajax for doing this job I mean to send the email to you.

djr33
05-23-2007, 03:44 AM
Grab the values of all the fields and send to a PHP mailer script via get (post?), using Ajax?

Seems like a lot of work.

I'd guess there's a better way to organize the whole system if we knew what you needed to do, overall.

ChrisWade
05-23-2007, 10:22 PM
I am doing the work for a Web Design Companies website that gets quote sent to them from a 3rd party source. (http://www.salesforce.com). The sales guy would like an email send to him with the same data that is sent to the 3rd party source. That way he doesnt have to check the 3rd party source after each submission.

So what I would like is something that can do that? You guys mentioned using a php script? Can you give me an example of that? I dont know anything about AJAX so I am at a loss there.

Thanks for the help.

StarrRider
05-24-2007, 04:12 AM
Chris
I stole this from an OS project called "Dandra Dev Snippets" - check SourceForge.net - the filename is sendmail.php and as you will see it's a couple of years old (No idea how long it's sat on my system - so it has probably been updated)


<?php /* (c) Copyright 2000,2001, Stefan Morgenroth, dandra.network, http://dandra.org */
// $Id: sendmail.php,v 1.4 2001/11/04 23:29:53 dandra Exp $ , $Revision: 1.4 $

/****************************************************************************
*
* sendmail - sending e-mails through a HTML formular
*
***************************************************************************/

/**
* The following values should be submited by the HTML form
* or will be fixed by removing the comment trailing the concerning line
**/
// $maildomain = 'domain.org';
// $recipient = 'contact';
// $mailsubject = '';
// $mailmessage = '';
// $lastname = '';
// $firstname = '';
// $email = '';
// $company = '';
// $priority = 3; // e-mail priority: 1: High, 3: Normal, 5: Low


$thankspageurl = 'http://www.domain.org/thanks.html';

// Text of error message
$alerterror = 'You forgot:';
$alerterror_missingfirstname = 'your first name!';
$alerterror_missinglastname = 'your last name!';
$alerterror_wrongemail = 'your valid e-mail address!';
$str_back = 'Back to last page';


//**** CHANGE THIS IF YOU WANT TO CHANGE THE MAIL RECIPIENTS ****//

// for eg. contact@domain.org
$targetuser[0] = 'contact'; // default recipient user
$targetuser[1] = 'contact';
$targetuser[2] = 'investors';
$targetuser[3] = 'postmaster';
$targetuser[4] = 'webmaster';
$targetuser[5] = 'admin';



//*********** DO NOT EDIT BEHIND THIS LINE ******************//


/* recipients */
/* to create multirecipient:
$recipient_mail .= "Mary <mary@u.college.edu>" . ", " ; // note the comma!
$recipient_mail .= "Kelly <kelly@u.college.edu>" . ", ";
$recipient_mail .= "anton@domain.org";
*/
// Build e-mail out of the recipient keyword
$recipient_mail == '';
if ($recipient != '')
{
switch ($recipient)
{
case $targetuser[1]: // e.g. mail to contact@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[2]: // e.g. mail to investors@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[3]: // e.g. mail to postmaster@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[4]: // e.g. mail to webmaster@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[5]: // e.g. mail to admin@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
default:
{
$recipient = $targetuser[0]; // mail to contact@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
}
}
}


/* subject */
// $subject = "Birthday Reminders for August";
// Build a structured subject
$subject = $maildomain.' > '.$recipient.' > '.substr($mailsubject, 0, 20);


/* message */
// Build the complex mailbody
/*
$message .= "The following email includes a formatted ASCII table\n";
$message .= "Day \t\tMonth \t\tYear\n";
$message .= "3rd \t\tAug \t\t1970\n";
$message .= "17rd\t\tAug \t\t1973\n";
*/
$message = '';
$message .= "\n";
$message .= $mailmessage;
$message .= "\n\n";

/* you can add a special signature */
/*
$message .= "--\r\n"; //Signature delimiter
$message .= "Birthday reminder copylefted by public domain";
*/
$message .= "___________________________\r\n"; //Signature delimiter
$message .= "dandra.sendertracking\r\n";
$message .= 'Referrer: '.getenv('HTTP_REFERER')."\n";
$message .= 'Browser: '.getenv('HTTP_USER_AGENT')."\n";
$message .= "RemoteAddr: ".getenv('REMOTE_ADDR');
$message .= "\t RemoteHost: ".getenv('REMOTE_HOST')."\n";


/* additional header pieces for errors, From cc's, bcc's, etc */
/*
$headers = "From: contact@domain.org"; // From to
$headers .= "cc: webmaster@domain.org\n"; // CC to
$headers .= "bcc: postmaster@domain.org, admin@php.net\n"; // BCCs to
$headers .= "X-Sender: <sender@anotherdomain.org>\n";
$headers .= "X-Mailer: dandra.network.mailer\n"; // mailer
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: <birthday@php.net>\n"; // Return path for errors
*/
/*
*/


if (($lastname != '') && ($firstname != '') && (($email != '') && ((strpos($email, '@') >= 2) && (strrpos($email, '.') >= 4))))
{
$sender_email = $email;
$headers = '';
$headers .= 'From: "'.$lastname.', '.$firstname.', '.$company.'" <'.$sender_email.'>'."\n";
// $headers .= 'Cc: "'.$name.', '.$vorname.', '.$firma.'" <'.$sender_email.'>'."\n";
// $headers .= 'Bcc: "'.$name.', '.$vorname.', '.$firma.'" <'.$sender_email.'>'."\n";
$headers .= "X-Sender: <".$sender_email.">\n";
$headers .= "X-Mailer: dandra.network.mailer.PHP".phpversion()."\n"; // mailer ID
$headers .= "User-Agent: ".getenv('HTTP_USER_AGENT')."\n";

/*
// Priority Level for the e-mail

X-Priority: 1
X-MSMail-Priority: High
X-Priority: 3
X-MSMail-Priority: Normal
X-Priority: 5
X-MSMail-Priority: Low

$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
*/
switch ($priority)
{
case 1:
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
break;
case 3:
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
break;
case 5:
$headers .= "X-Priority: 5\n";
$headers .= "X-MSMail-Priority: Low\n";
break;
default:
{
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
}
}
$headers .= "Return-Path: <".$sender_email.">\n"; // Return path for errors

/* If you want to send html mail, uncomment the following line */
// $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type

/* and now mail it */
// mail($recipient, $subject, $message, $headers);
if ($recipient_mail != '')
{
// mail($recipient_mail, $subject, $message, $headers);
if (mail($recipient_mail, $subject, $message, $headers))
{
header('Location: '.$thankspageurl);
}
}

}
else
{
$alerterror_out = '';
echo '<script language="JavaScript">';
$alerterror_out .= $alerterror.' ';
echo "alert(' ".$alerterror_out;
if ($lastname == '')
{
// $alerterror_out .= $alerterror_missinglastname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missinglastname.' ';
}
if ($firstname == '')
{
// $alerterror_out .= $alerterror_missingfirstname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missingfirstname.' ';
}
if ((strpos($email, '@') < 2) && (strrpos($email, '.') < 4))
{
// $alerterror_out .= $alerterror_wrongemail;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_wrongemail.' ';
}
echo " ');";
// echo "alert(' ".$alerterror_out." ');";
echo 'history.back();';
echo '</script>';
echo '<noscript>';
echo '<h2>'.$alerterror_out;
if ($lastname == '')
{
// $alerterror_out .= $alerterror_missinglastname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missinglastname.' ';
}
if ($firstname == '')
{
// $alerterror_out .= $alerterror_missingfirstname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missingfirstname.' ';
}
if ((strpos($email, '@') < 2) && (strrpos($email, '.') < 4))
{
// $alerterror_out .= $alerterror_wrongemail;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_wrongemail.' ';
}
echo '</h2>';
echo '<h3><a href="'.$HTTP_REFERER.'" title="'.$str_back.'">'.$str_back.'</a></h3>';
echo '</noscript>';
}