andrej13 Posted January 25, 2011 Share Posted January 25, 2011 Hey folks, I made a small shopping cart but I struggle with receiving an email with the orders; thanks in advance this is the mail.php <?php session_start(); if($_POST['sendemail'] == 'Email') { $headers = 'From: Sender <[email protected]>'; mail('[email protected]', 'Subject', $_SESSION["cart"], $headers); echo "DEBdsUG".$_POST["cart"]; echo 'Your mail has been sent'; } else { echo 'Your mail was not sent'; } ?> this is the cart.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Cart</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to bookshop...</a></p> <form action="mail.php" method="post"> <input type="submit" name="sendemail" value="Email" /> <input type="hidden" name="cart" value="<?= $cart; ?>" /> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/225626-i-dont-receive-email-from-mailphp/ Share on other sites More sharing options...
hiprakhar Posted January 25, 2011 Share Posted January 25, 2011 Try this: $to = "[email protected]"; $subject = "Your subject line"; $message = "<html> <head> <title>Email Confirmation</title> </head> <body> your message which may be HTML. Remember to use single quotes '' in your HTML text otherwise they will conflict with outer double quotes. Or escape quotes. </body>"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: "your email address" <[email protected]>' . "\r\n"; //$headers .= 'Cc: ' . "\r\n"; mail($to,$subject,$message,$headers); Do not use session values directly in mail function. Sanitise the values before using them. If in doubt use echo to figure out what values are actually going inside the mail function. Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/225626-i-dont-receive-email-from-mailphp/#findComment-1164997 Share on other sites More sharing options...
andrej13 Posted January 25, 2011 Author Share Posted January 25, 2011 Try this: $to = "[email protected]"; $subject = "Your subject line"; $message = "<html> <head> <title>Email Confirmation</title> </head> <body> your message which may be HTML. Remember to use single quotes '' in your HTML text otherwise they will conflict with outer double quotes. Or escape quotes. </body>"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: "your email address" <[email protected]>' . "\r\n"; //$headers .= 'Cc: ' . "\r\n"; mail($to,$subject,$message,$headers); Do not use session values directly in mail function. Sanitise the values before using them. If in doubt use echo to figure out what values are actually going inside the mail function. Hope that helps thanks but I still don't receive the mail. Quote Link to comment https://forums.phpfreaks.com/topic/225626-i-dont-receive-email-from-mailphp/#findComment-1165000 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2011 Share Posted January 25, 2011 If the To: and From: email address are at gmail, like you show in your post, are you sending this email using a gmail mail server? If not, gmail will discard your email because it knows that the actual sending mail server is not a gmail mail server. You must put an email address that at least has a domain that corresponds to your sending mail server into the From: address header. Quote Link to comment https://forums.phpfreaks.com/topic/225626-i-dont-receive-email-from-mailphp/#findComment-1165003 Share on other sites More sharing options...
andrej13 Posted January 25, 2011 Author Share Posted January 25, 2011 If the To: and From: email address are at gmail, like you show in your post, are you sending this email using a gmail mail server? If not, gmail will discard your email because it knows that the actual sending mail server is not a gmail mail server. You must put an email address that at least has a domain that corresponds to your sending mail server into the From: address header. You can call that a Solve thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/225626-i-dont-receive-email-from-mailphp/#findComment-1165007 Share on other sites More sharing options...
hiprakhar Posted January 25, 2011 Share Posted January 25, 2011 If the To: and From: email address are at gmail, like you show in your post, are you sending this email using a gmail mail server? If not, gmail will discard your email because it knows that the actual sending mail server is not a gmail mail server. You must put an email address that at least has a domain that corresponds to your sending mail server into the From: address header. I dont think so thats the problem as I myself use gmail address in From: and mails are sent without fail. @andrej13 if this is not working then maybe something is wrong with your hosting server which you are using to send mails, as this is a working code and I am using it to send mails myself. Ensure that mail() is enabled by your server. use phpinfo() to find that. Quote Link to comment https://forums.phpfreaks.com/topic/225626-i-dont-receive-email-from-mailphp/#findComment-1165009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.