PHP Sendgrid

I am using a mail service called SendGrid.  I am running into a few problems evn after following the documentation to a "T".
$email = new SendGrid\Email();

$fname = $_POST['item_options[first_name]'];
$lname = $_POST['item_options[last_name]'];

$fullname = $fname. '' . $lname;

if(isset($_POST['item_options[gender]'])) {
	$gender = $_POST['item_options[gender]'];
} else {
	$gender= '';	
}

if(isset($_POST['item_options[marital_status]'])) {
	$marital_status = $_POST['item_options[marital_status]'];
} else {
	$marital_status = '';	
}

if(isset($_POST['minors'])) {
	$minors = $_POST['minors'];
} else {
	$minors = '';	
}
$professional_cyclist = $_POST['professional_cyclist'];
$triathlete = $_POST['triathlete'];

if(isset($_POST['association_membership'])) {
		$association_membership = $_POST['association_membership'];
	} else {
		$association_membership = '';	
	}
	
$product_deductible = $_POST['product_deductible'];

if(isset($_POST['product_liability'])) {
	$product_liability = $_POST['product_liability'];	
} else {
	$product_liability = '';	
}
if(isset($_POST['product_medical'])) {
		$product_medical = $_POST['product_medical'];
	} else {
		$product_medical = '';	
	}
if(isset($_POST['product_contact'])) {
	$product_contact = $_POST['product_contact'];	
} else {
	$product_contact = '';	
}


$type_bicycle = $_POST['type_bicycle'];


if(isset($_POST['year_built'])) {
	$year_built = $_POST['year_built'];
} else {
	$year_built = '';	
}

if(isset($_POST['manufacturer'])) {
	$model = $_POST['model'];
	} else {
		$model = '';
		}

if(isset($_POST['serial_number'])) {
	$serial_number = $_POST['serial_number'];
	} else {
		$serial_number = '';
	}

$bicycle_material = $_POST['bicycle_material'];
$usage = $_POST['usage'];

if(isset($_POST['purchase_date'])) {
	$purchase_date = $_POST['purchase_date'];
} else {
	$purchase_date = '';
}	
if(isset($_POST['purchase_price'])) {
	$purchase_price = $_POST['purchase_price'];
} else {
	$purchase_price = '';	
}

$used = $_POST['used'];


if(isset($_POST['accessories_value'])) {
	$accessories_value = $_POST['accessories_value'];
} else {
	$accessories_value = '';	
}

if(isset($_POST['attached_accessories'])) {
	$attached_accessories = $_POST['attached_accessories'];
} else {
	$attached_accessories = '';	
}

$bicycle_location = $_POST['bicycle_location'];
$location_address = $_POST['location_address'];
$location_city = $_POST['location_city'];
$location_state = $_POST['location_state'];
$location_zip = $_POST['location_zip'];
$contact_email = $_POST['email_address'];


$email
    ->addTo('robert@baycreative.com')
    ->addTo('rgranlund@rockintuit.com')
    ->setFrom('sales@spokeinsurance.com')
    ->setSubject('Spoke Sales Lead')
	->setHtml('<b>Name::</b> '.$fullname)
	->setHtml('<b>Email:: </b> '.$contact_email)
	->setHtml('<b>Gender:: </b> '.$gender)
	->setHtml('<b>Marital Status:: </b> '.$marital_status) 
	->setHtml('<b>Minors:: </b> '.$minors)	
	->setHtml('<b>Professional Cyclist:: </b> '.$professional_cyclist) 
	->setHtml('<b>Triathlete:: </b> '.$triathlete)
	->setHtml('<b>Association Membership:: </b> '.$association_membership)
	->setHtml('<b>Deductible:: </b> '.$product_deductible)
	->setHtml('<b>Liability:: </b> '.$product_liability) 
	->setHtml('<b>Medical:: </b> '.$product_medical)
	->setHtml('<b>Contact:: </b> '.$product_contact) 
	->setHtml('<b>Type of Bicycle:: </b> '.$type_bicycle)
	->setHtml('<b>Year Built:: </b> '.$year_built)
	->setHtml('<b>Model:: </b> '.$model)
	->setHtml('<b>Serial Number:: </b> '.$serial_number)
	->setHtml('<b>Bicycle Material:: </b> '.$bicycle_material)
	->setHtml('<b>Usage:: </b> '.$usage)
	->setHtml('<b>Purchase Date:: </b> '.$purchase_date)
	->setHtml('<b>Purchase Price:: </b> '.$purchase_price)	
	->setHtml('<b>New or Used:: </b> '.$used) 
	->setHtml('<b>Accessories Value:: </b> '.$accessories_value) 
	->setHtml('<b>Attached Accessories:: </b> '.$attached_accessories)
	->setHtml('<b>Bicycle Location:: </b> '.$bicycle_location) 
	->setHtml('<b>Location Address:: </b> '.$location_address) 
	->setHtml('<b>Location City:: </b> '.$location_city) 
	->setHtml('<b>Location State:: </b> '.$location_state)
	->setHtml('<b>Location Zip:: </b> '.$location_zip);


$sendgrid->send($email);

Open in new window


1. When It sends an email it only sends the last line: ->setHtml('<b>Location Zip:: </b> '.$location_zip);
2. Are these two lines formatted correctly?
$fname = $_POST['item_options[first_name]'];
$lname = $_POST['item_options[last_name]'];
LVL 7
rgranlundAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
1. Try combining all the lines of content into a single variable and then pass that variable to setHtml.
2. Probably not. If you have a multi-dimensional array, try:
$fname = $_POST['item_options']['first_name'];

If that doesn't work, then try doing print_r($_POST); and posting the resulting content here.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.