Jump to content

[SOLVED] sending email from webpage, part 2


bossman

Recommended Posts

hello all, since my last post i have managed to get my email form up and running, uploading files to a database and to a directory on the server, and the email is formatted nicely with html and sends to a single user flawlessly.

 

The new problem...

 

we want to set it up so that when you hit submit on the form you fill out, it send the email out to 2 people. I can't get it to send to both addresses, only one each time. Im sorry for the lengthy code, but if anybody can take a look at this and give me some suggestions on what to do to get it working i would appreciate it.

 

here's the code for the dropdown you select. the field marketing manager filling out the request will select themself from this dropdown...(im using my personal email address right now just for testing purposes)....

 

<form action="send_request_4.php" method="post" enctype="multipart/form-data" id="myform">
<label><strong>Field Marketing Manager:</strong></label><br/>
<select name="1_mark_manager">
<option value="Zarnaz Arlia <opusrandy@gmail.com>">Zarnaz Arlia</option>
<option value="Susanna Church <opusrandy@gmail.com>">Susanna Church</option>
<option value="Nico Juber <opusrandy@gmail.com>">Nico Juber</option>
<option value="Amanda Lowe <opusrandy@gmail.com>">Amanda Lowe</option>
<option value="Shawna McGrath <opusrandy@gmail.com>">Shawna McGrath</option>
<option value="Lisa Parillo <opusrandy@gmail.com>">Lisa Parillo</option>
<option value="Ozlem Yilmaz <opusrandy@gmail.com>">Ozlem Yilmaz</option>
</select>
<br/><br/>

 

what happens is not only does it pass the variable to the email to display which field marketing manager is making the request, but it uses the email address to fill in the $tocc variable and $nametocc variable

 

here is the php that handles the form...

 

<?php
$h="------";
$u="------";
$p="------";
$d="------";

$link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later");
mysql_select_db($d, $link);
?>

<?php
error_reporting(E_ALL ^ E_NOTICE);
//new function

//retrieve vital header information
$to = "rkettering@jpenterprises.com";
$nameto = "Randy Kettering";
$tocc = $_POST['1_mark_manager'];
$nametocc = "Randy Kettering";
$from = "admin@adobedayevents.com";
$namefrom = "Adobe Day Events Administrator";
$subject = "Project Request";

//retrieve variables from the form
$field_mark_manager = $_POST['1_mark_manager']; 
$comp_cust_name = $_POST['company_customer_name'];
$materials = $_POST['materials'];
$icf_source_code = $_POST['icf_source_code'];
$lead_code = $_POST['lead_code'];
$product_interest = $_POST['product_interest'];
$add_product_interest = $_POST['additional_product_interest'];
$number_of_units = $_POST['2_units_number'];
$purchase_timeline = $_POST['3_purchase_timeline'];
$industry = $_POST['4_industry'];
$employee_range = $_POST['5_employee_range'];
$revenue_range = $_POST['6_revenue_range'];
$due_date_month = $_POST['7_month'];
$due_date_day = $_POST['8_day'];
$due_date_year = $_POST['9_year'];
$additional_comm = $_POST['additional_comments'];

//retrieve file paths from the file upload text fields.
//$new_upload_materials = $_POST['upload_materials'];

// BEGIN stuff to upload first file to directory...
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['upload_materials']['name']); 

if(move_uploaded_file($_FILES['upload_materials']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['upload_materials']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

//BEGIN stuff to upload second file to directory
$target_path2 = "applicable_lists/";

$target_path2 = $target_path2 . basename( $_FILES['upload_lists']['name']); 

if(move_uploaded_file($_FILES['upload_lists']['tmp_name'], $target_path2)) {
    echo "The file ".  basename( $_FILES['upload_lists']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}


//post file to database
$new_upload =$HTTP_POST_FILES['upload_materials']['name'];

$new_list=$HTTP_POST_FILES['upload_lists']['name'];


//query to insert files and info into database
$query = "INSERT INTO uploads (month, day, year, upload_file, upload_list)
VALUES
('$due_date_month', '$due_date_day', '$due_date_year', '$new_upload', '$new_list')";

$result=mysql_query($query);

mysql_close($link);


//code to call all the variables and compile the email message
$message = "<strong>Field Marketing Manager:</strong> $field_mark_manager<br />
<strong>Company/Customer Name:</strong> $comp_cust_name<br />
<strong>ICF Source Code:</strong> $icf_source_code<br />
<strong>Lead Code:</strong> $lead_code<br />
<strong>Product Interest:</strong> $product_interest<br />
<strong>Additional Product Interest:</strong> $add_product_interest<br />
<strong>Number of Units:</strong> $number_of_units<br />
<strong>Purchase Timeline:</strong> $purchase_timeline<br />
<strong>Industry:</strong> $industry<br />
<strong>Employee Range:</strong> $employee_range<br />
<strong>Revenue Range:</strong> $revenue_range<br />
<strong>Due Date:</strong> $due_date_month $due_date_day, $due_date_year<br />
<strong>Additional Comments:</strong> $additional_comm<br /><br />
<strong>Uploaded Files:</strong><br /><br />
$new_upload<br /><br />
<strong>Uploaded Applicable Lists:</strong><br /><br />
$new_list<br /><br />

<strong>Materials Required:</strong><br /><br />";

//code to call in checkbox information
while($check_materials = current($materials))
{  
echo key($materials);  echo "<br/>";
if(key($materials) == '.html email invitation' && $check_materials == 1) {  $material1 = ".html email invitation<br />";  }
else if(key($materials) == 'Agenda' && $check_materials == 1) { $material2 = "Agenda<br />"; } 
else if(key($materials) == 'Registration site (confirmation email, (2) reminder emails)' && $check_materials == 1) { $material3 = "Registration site (confirmation email, (2) reminder emails)<br />"; } 
else if(key($materials) == 'Thank You Emails' && $check_materials == 1) { $material4 = "Thank You Emails<br />"; }
else if(key($materials) == 'Signage' && $check_materials == 1) { $material5 = "Signage<br />"; }
else if(key($materials) == 'Email Broadcast(s)' && $check_materials == 1) { $material6 = "Email Broadcast(s)<br />"; }
else if(key($materials) == 'Report prep/upload' && $check_materials == 1) {$material7 = "Report prep/upload<br /><br />"; }
next($materials);

}
authSendEmail($from, $namefrom, $to, $nameto, $tocc, $nametocc, $subject, $message, $material1, $material2, $material3, $material4, $material5, $material6, $material7);
?>

<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
//logArray - connection,
function authSendEmail($from, $namefrom, $to, $nameto, $tocc, $nametocc, $subject, $message, $material1, $material2, $material3, $material4, $material5, $material6, $material7)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "------";
$port = "------";
$timeout = "------";
$username = "------";
$password = "------";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */
//
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>, To: $nametocc <$tocc>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//Construct Email
fputs($smtpConnect, "To: $to, $tocc\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n$material1\n$material2\n$material3\n$material4\n$material5\n$material6\n$material7\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}

//echo "<meta http-equiv='refresh' content='0;URL=http://www.adobedayevents.com/project_request/request_sent.php'>";
?>

 

thank you

Link to comment
Share on other sites

Sorry for not going though your code in depth but you can send as many emails as you want.

 

mail(($to1,$subject, $message, $headers);

mail(($to2,$subject, $message, $headers);

 

you can send as many as you want. You could go through a loop of email to's

 

Can't see why there is a problem.

 

Desmond.

 

Link to comment
Share on other sites

hmmm...im still having problems, i added the CC: everywhere, and now i can't get it to send an email at all now. not to my $to or to me $tocc

 

I made some changes to the code as well, i will mark where i made my changes

 

<?php
$h="---";
$u="---";
$p="---";
$d="---";

$link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later");
mysql_select_db($d, $link);
?>

<?php
error_reporting(E_ALL ^ E_NOTICE);
//new function

//retrieve vital header information
$to = "rkettering@jpenterprises.com";
$nameto = "Randy Kettering";
$tocc = $_POST['1_mark_manager'];
$nametocc = "Randy Kettering";
$from = "admin@adobedayevents.com";
$namefrom = "Adobe Day Events Administrator";
$subject = "Project Request";

//retrieve variables from the form
$field_mark_manager = $_POST['1_mark_manager']; 
$comp_cust_name = $_POST['company_customer_name'];
$materials = $_POST['materials'];
$icf_source_code = $_POST['icf_source_code'];
$lead_code = $_POST['lead_code'];
$product_interest = $_POST['product_interest'];
$add_product_interest = $_POST['additional_product_interest'];
$number_of_units = $_POST['2_units_number'];
$purchase_timeline = $_POST['3_purchase_timeline'];
$industry = $_POST['4_industry'];
$employee_range = $_POST['5_employee_range'];
$revenue_range = $_POST['6_revenue_range'];
$due_date_month = $_POST['7_month'];
$due_date_day = $_POST['8_day'];
$due_date_year = $_POST['9_year'];
$additional_comm = $_POST['additional_comments'];

//retrieve file paths from the file upload text fields.
//$new_upload_materials = $_POST['upload_materials'];

// BEGIN stuff to upload first file to directory...
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['upload_materials']['name']); 

if(move_uploaded_file($_FILES['upload_materials']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['upload_materials']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

//BEGIN stuff to upload second file to directory
$target_path2 = "applicable_lists/";

$target_path2 = $target_path2 . basename( $_FILES['upload_lists']['name']); 

if(move_uploaded_file($_FILES['upload_lists']['tmp_name'], $target_path2)) {
    echo "The file ".  basename( $_FILES['upload_lists']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}


//post file to database
$new_upload =$HTTP_POST_FILES['upload_materials']['name'];

$new_list=$HTTP_POST_FILES['upload_lists']['name'];


//query to insert files and info into database
$query = "INSERT INTO uploads (month, day, year, upload_file, upload_list)
VALUES
('$due_date_month', '$due_date_day', '$due_date_year', '$new_upload', '$new_list')";

$result=mysql_query($query);

mysql_close($link);


//code to call all the variables and compile the email message
$message = "<strong>Field Marketing Manager:</strong> $field_mark_manager<br />
<strong>Company/Customer Name:</strong> $comp_cust_name<br />
<strong>ICF Source Code:</strong> $icf_source_code<br />
<strong>Lead Code:</strong> $lead_code<br />
<strong>Product Interest:</strong> $product_interest<br />
<strong>Additional Product Interest:</strong> $add_product_interest<br />
<strong>Number of Units:</strong> $number_of_units<br />
<strong>Purchase Timeline:</strong> $purchase_timeline<br />
<strong>Industry:</strong> $industry<br />
<strong>Employee Range:</strong> $employee_range<br />
<strong>Revenue Range:</strong> $revenue_range<br />
<strong>Due Date:</strong> $due_date_month $due_date_day, $due_date_year<br />
<strong>Additional Comments:</strong> $additional_comm<br /><br />
<strong>Uploaded Files:</strong><br /><br />
$new_upload<br /><br />
<strong>Uploaded Applicable Lists:</strong><br /><br />
$new_list<br /><br />

<strong>Materials Required:</strong><br /><br />";

//code to call in checkbox information
while($check_materials = current($materials))
{  
echo key($materials);  echo "<br/>";
if(key($materials) == '.html email invitation' && $check_materials == 1) {  $material1 = ".html email invitation<br />";  }
else if(key($materials) == 'Agenda' && $check_materials == 1) { $material2 = "Agenda<br />"; } 
else if(key($materials) == 'Registration site (confirmation email, (2) reminder emails)' && $check_materials == 1) { $material3 = "Registration site (confirmation email, (2) reminder emails)<br />"; } 
else if(key($materials) == 'Thank You Emails' && $check_materials == 1) { $material4 = "Thank You Emails<br />"; }
else if(key($materials) == 'Signage' && $check_materials == 1) { $material5 = "Signage<br />"; }
else if(key($materials) == 'Email Broadcast(s)' && $check_materials == 1) { $material6 = "Email Broadcast(s)<br />"; }
else if(key($materials) == 'Report prep/upload' && $check_materials == 1) {$material7 = "Report prep/upload<br /><br />"; }
next($materials);

}
authSendEmail($from, $namefrom, $to, $nameto, $tocc, $nametocc, $subject, $message, $material1, $material2, $material3, $material4, $material5, $material6, $material7); <-------------CHANGED
?>

<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
//logArray - connection,
function authSendEmail($from, $namefrom, $to, $nameto, $tocc, $nametocc, $subject, $message, $material1, $material2, $material3, $material4, $material5, $material6, $material7) <------------CHANGED
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "---";
$port = "---";
$timeout = "---";
$username = "---";
$password = "---";
$localhost = "---";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */
//
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine . "RCPT CC: $tocc" . $newLine); <---------------CHANGED
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine . "CC: $nametocc <$tocc>" . $newLine; <-----------CHANGED
$headers .= "From: $namefrom <$from>" . $newLine;

//Construct Email
fputs($smtpConnect, "To:\n$to CC: $tocc\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n$material1\n$material2\n$material3\n$material4\n$material5\n$material6\n$material7\n.\n"); <---------------CHANGED
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}

//echo "<meta http-equiv='refresh' content='0;URL=http://www.adobedayevents.com/project_request/request_sent.php'>";
?>

 

Can anyone help me figure out why its not working now?

Link to comment
Share on other sites

//retrieve vital header information
$to = "rkettering@jpenterprises.com";
$to = $_POST['1_mark_manager'];
$nameto = "Randy Kettering";
$from = "admin@adobedayevents.com";
$namefrom = "Adobe Day Events Administrator";
$subject = "Project Request";

 

im not quite sure what my problem is...now i can get it to send to the 1_mark_manager but it wont send to ME, which is the first $to up there, i used the code you posted above but when i used it, it didn't send out ANYTHING to either of the email addresses

Link to comment
Share on other sites

note the .= i have in my code.

 

try this, i had a typo in my code:

 

<?php
$to  = 'someone@somewhere.com' . ', ';
$to .= 'someone_else@somewhere.com';
?>

 

the .= concats the strings together.  the same as writing $to out as one:

 

<?php
$to = 'someone@somewhere.com' . ', ' . 'someone_else@somewhere.com';
?>

 

got it?

Link to comment
Share on other sites

the only different between wut you posted and what i have is the fact that for the second recipient, im pulling a variable from the form.

 

$to = "rkettering@jpenterprises.com" . ',' . $_POST['1_mark_manager'];

 

is there a different procedure for if your doing what im trying to do with the $_POST?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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