Page 1 of 1

send to db & email?

Posted: Thu Sep 11, 2003 4:05 pm
by planethax
Ok, I had 2 Forms on my site, one used MailForm.pl script to email me users info.
And now I have also added a .php form that send the users info to the data base.

My question is: how can I get it to do both requests, send to database and email me the info,
can I combine the perl and php scripts or is there a better way in php to have the data sent to both the database and my email?
The code I have for the php that send to db is

Code: Select all

{
include("config.php");
$connection = mysql_connect("$server", "$db_user", "$db_pass");
$db = mysql_select_db("$database", $connection);
$query = "INSERT INTO login (`username`,`password`,`fname`,`sname`,`email`,`emailz`,`country`,`city`,`interests`,`street`,`prov`,`street2`,`post`,`phone`,`fax`,`hpage`,`pubs`,`clubs`,`dances`,`emale`,`efemale`,`eboth`,`mcountry`,`mrock`,`mhiphop`,`mdance`,`mrap`,`bgrills`,`mmetal`)".
  "VALUES ('$username', '$password', '$fname','$sname', '$emaila', '$emailz', '$country', '$city',  '$interests', '$street', '$prov', '$street2', '$post', '$phone', '$fax', '$hpage', '$pubs', '$clubs', '$dances', '$emale',  '$efemale', '$eboth', '$mcountry', '$mrock', '$mhiphop', '$mdance', '$mrap', '$bgrills', '$mmetal')";
$result = mysql_query($query, $connection);

echo "$langїthanksregister]";

	$ida= uniqid('message');
	$ida2= uniqid('$ida');
	$nr= uniqid($ida);
	$date=date('m.j.Y');

$connection = mysql_connect("$server", "$db_user", "$db_pass");
$db = mysql_select_db("$database", $connection);
$query = "SELECT * FROM usermessages";
$query = "INSERT INTO usermessages (`nomer`, `to`, `from`, `date`, `title`, `message`, `new`) VALUES ('$nr', '$username', 'admin', '$date', '$langїadminwelcome]', '$langїadminwelcomemessage]', 'yes')";
$result = mysql_query($query, $connection);
} ї/code} 
The perl mailForm.pl just called &#1111;code]<form method='post' action="/td/scriptcss/FormMail.pl">
with a submit button
any suggestions will be appreciated.

simplified

Posted: Thu Sep 11, 2003 4:10 pm
by planethax
ok sorry, guess what I am asking is:
Can I put 2 actions in 1 form, combine these two together somehow?

Code: Select all

<form method='post' action="/td/scriptcss/FormMail.pl">

Code: Select all

<form action="reg.php" method="post">

Posted: Thu Sep 11, 2003 4:45 pm
by Bizwala
I don't think that can be done. You would be best of doing 1 of the following:

1. Use Perl:DBI and run a perl mysql function in FormMail.pl
2. Create a mail() function in reg.php

I would go with 2, you can find details on how to use mail() at php.net. (Just FYI. when you run a search for mail() at PHP.net click the mail() link on the page it refers you to.)

Lani

Ok heres what I have

Posted: Thu Sep 11, 2003 6:12 pm
by planethax
I am very new at this (couple days) but I want to learn and dont expect others to do my work for me, I read the info at php.net and this is what I got out of it

On the reg.php that I am posting to the data base if I ad this code

Code: Select all

<?php
mail("tdclub@planethax.com", "New Member", $username $password $fname $sname $emaila $emailz $country $city $interests $street 

$prov $street2 $post $phone $fax $hpage $pubs $clubs $dances $emale $efemale $eboth $mcountry $mrock $mhiphop 

$mdance $mrap $bgrills $mmetal,
     "From: $emaila\r\n"
    ."Reply-To: $emaila\r\n"
    ."X-Mailer: PHP/" . phpversion());
?>
That should work shouldnt it?
I guess I must have it all wrong :(

Posted: Thu Sep 11, 2003 6:24 pm
by planethax
I am getting a
Parse error: parse error in /home/httpd/vhosts/planethax.com/httpdocs/td/reg.php on line 141
and line 141 is the second line of that above snippit

Posted: Thu Sep 11, 2003 6:29 pm
by Bizwala
<?php
mail("tdclub@planethax.com", "New Member", $username $password $fname $sname $emaila $emailz $country $city $interests $street

$prov $street2 $post $phone $fax $hpage $pubs $clubs $dances $emale $efemale $eboth $mcountry $mrock $mhiphop

$mdance $mrap $bgrills $mmetal,
"From: $emaila\r\n"
."Reply-To: $emaila\r\n"
."X-Mailer: PHP/" . phpversion());
?>
try this:

Code: Select all

$subject="New Member";

//Build your email BODY and assign to var $message
$message.="Build your message body here \n"
$message.="If you are sending yourself text format then use '\n' to seperate your lines\n";
$message.="Username: $username\n";
$message.="First Name: $fname\n";
//Continue until you are satisfied with your message body

$headers.="From: $username <$email>\r\n"; // where $server_email could be any email address on the server i.e. webmast@domain.com or even the users email i.e $email
$headers.="Reply-To: $email\r\n";
// You can find more mail headers at PHP.net

//Formulate mail function here
$send=mail($where_you_want_the_email_sent,$subject,$message,$headers);
That should give you a good start.[/quote]

Posted: Thu Sep 11, 2003 8:41 pm
by planethax
thank you very much, it was a great starting point, I had alot of errors I had to work through but I am still getting an parse error on last line

Code: Select all

$send=mail(tdclub@planethax.com,$subject,$message,$headers);
I tried
$send=mail($tdclub@planethax.com,$subject,$message,$headers);
and even tried

Code: Select all

$toemail="tdclub@planethax.com"
$send=mail($toemail,$subject,$message,$headers);
with out any luck, any ideas? thanks

Code: Select all

<?php 
$subject="New Member"; 

//Build your email BODY and assign to var $message 
$message.="There has been a new Member register for tdc \n"; 
$message.=" Here are the Details of the new member\n"; 
$message.="Username: $username\n"; 
$message.="Password: $password\n";
$message.="First Name: $fname\n";
$message.="Sir Name Name: $sname\n";
$message.="EmailA : $emaila\n";
$message.="EmailZ: $emailz\n";
$message.="Street: $street\n";
$message.="Street2: $street2\n";
$message.="City: $city\n";
$message.="Prov: $prov\n";
$message.="Country: $country\n";
$message.="Postal Code: $post\n";
$message.="Misc: $phone $fax $hpage\n";
$message.="Interests: $pubs $clubs $dances $bgrills\n";
$message.="Exotic Dancers: $emale $efemale $eboth\n";
$message.="Bands: $mcountry $mrock $mhiphop $mdance $mrap $mmetal\n";
$message.="Comments: $interests\n";
//Continue until you are satisfied with your message body 
$headers.="From: $emaila\r\n";
$headers.="Reply-To: $emaila\r\n"; 
// You can find more mail headers at PHP.net 

//Formulate mail function here 
$send=mail(tdclub@planethax.com,$subject,$message,$headers);
?> 

?>

Posted: Thu Sep 11, 2003 8:50 pm
by Bizwala
put your email address in "quotes"

"you@domain.com"

Posted: Thu Sep 11, 2003 9:45 pm
by planethax
thats great thank you very much, works they way I wanted it to!
one last quick question, can I have it send the email to 2 addys, like bake to the user $emaila ? thanks again

Posted: Thu Sep 11, 2003 9:52 pm
by Bizwala
mmhmm

add CC: $emaila\r\n to your mail headers

Posted: Thu Sep 11, 2003 10:21 pm
by planethax
ahhh ok sorry, silly question. Thanks for all your help.