Forum Moderators: coopster

Message Too Old, No Replies

php mail function - use different subject based on the recipients

         

webtown06

6:53 am on Aug 11, 2007 (gmt 0)

10+ Year Member



Hello everyone:

I am wondering if there is a way to use different suject line for different recipients.

I am using PHP mail function to send out email which confirm account registration.

Email
will be send to students who registered an account, the lab assistant will also get an

email
contain the same account registration information.

I want use different subject line for student and lab assistant.
Would it be possible to achieve this by using one mail function? Please give me some

advises.

If you know some online resource discuss this topic please let me know. Thanks for your

help!

PHP code I used for mail function.

$mailto = "$email";
$subject = "Computer Lab Account Registration Confirmation Email";
$message = "";
$under_gradAccount ="";
$gradAccounts = "";
$gradAccount1 = "";

/*
note: you need to include MIME type and content-type in order to
include message body fomatted with html tags.
Add multiple recipents in header portion
*/
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $fname $lname <$email>\n";
$header.="Bcc:santa98bn@yahoo.com\n";

print ("First name: $fname. <br />");
print ("Last name: $lname. <br />");

print ("Gender: $gender. <br />");

print("Age: $age. <br />");

print ("Department: $departments. <br />");

print ("Email: $email. <br />");

print ("Phone number: $phone_num. <br />");

if($class_standing == "undergraduate")
{
print "You are an $class_standing student.<br /> You applied for the following

account(s):<br />";

if(is_array($_POST['undergrad_account']))
{
foreach($_POST['undergrad_account'] as $undergradAccount)
{
print ("$undergradAccount<br />");
}
}

}

if($class_standing == "graduate")
{
print ("You are a $class_standing student.<br /> You applied for the following

account(s):<br />");

if(is_array($_POST['undergrad_account']))
{
foreach($_POST['undergrad_account'] as $undergradAccount)
{
print ("$undergradAccount<br />");
}
}

if(is_array($_POST['grad_account']))
{
foreach($_POST['grad_account'] as $gradAccount)
{
print ("$gradAccount<br />");
}
}
}

$message ="<html><body>";
$message .="<h4>Please verify your account information.<br />If you have any

questions, please contact <a href=\"mailto:flashqa3@yahoo.com\">Computer Lab Account

Service</a>.</h4>";
$message .="<hr style=\"color: orange; width: 800px;\" />";
$message .= "First name: $fname. <br />";
$message .= "Last name: $lname. <br />";
$message .= "Gender: $gender. <br />";
$message .= "Age: $age. <br />";
$message .= "Department: $departments. <br />";
$message .= "Email: $email. <br />";
$message .= "Phone: $phone_num. <br />";

$message .= "You are a(n): $class_standing student. <br />";
$message .= "You applied for the following accounts: <br />";
//use implode function to convert array to string, so account option
//can be displayed in the email
if($class_standing == "undergraduate")
{
if(is_array($_POST['undergrad_account']))
{
$under_gradAccount .= implode(', ', $_POST['undergrad_account']); //convert

undergraduate account option from an array into a string
$message .= "--". $under_gradAccount."<br />";
}

}

/*
convert graduate account into a string format
*/
if($class_standing == "graduate")
{
//test to see if undergraduate checkbox group being checked
if(is_array($_POST['undergrad_account']))
{
$gradAccount1 .= implode(', ', $_POST['undergrad_account']);
}
else
$gradAccount1 = "";

if(is_array($_POST['grad_account']))
{
$gradAccounts .= implode(', ', $_POST['grad_account']);
}

$message .= "--".$gradAccount1 . '<br />';
$message .= "--".$gradAccounts.'<br />';
}

if(empty($comments))
{
print "You did not enter any comments.";
}

if(!empty($comments))
{
$message .= "Your comments on our account services are shown below:<br />";
$message .= "' $comments'<br />";
}

$message .= "The services you requested will be available once we approve your

application.";
$message .="<hr style=\"color: orange; width: 800px;\" />";

$message .= "<br /><br />Computer Lab Account Services<br />San Jose State

University";

$message .="</body></html>";

?>

Dragosh

7:05 am on Aug 11, 2007 (gmt 0)

10+ Year Member



Lets suppose $student is for student and $labassistant is for lab assistant.
suppose you had a selection box,name="person", to choose between student and lab assistant.
i think that looked like that:
if($_REQUEST["person"]=="student")
$subject="Student...";
elseif($REQUEST["person"]=="lab assistant")
$subject="Lab assistant...";
else echo "Choose something from selection box";

Habtom

3:30 pm on Aug 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Like Dragosh mentioned above, the way forward is put your subject in if condition or case, and assign it variably based on any selection.

In some of my websites I try to include a few more info into the subject including Order Numbers, Full Name, and this kind of related information which can let me know what the content is exactly about. In some, I have options showing the nature of the message like "Express", "Regular", . . .

Habtom