duxbox Posted July 24, 2009 Share Posted July 24, 2009 Hello everyone, Lets say, every time my website sends out an automated email notification to the members, these emails appear as eg. [email protected] in their email inbox email list. This is actually before you click on the email to open it. I tested it in Yahoo! and Hotmail and both show [email protected], but Gmail is even worst, it takes the first part of the email and only shows info when previewing your emails. instead of the plain email address or just showing the word "info" like the case in Gmail. This is more a cosmetic thing but I would like it to work like any other professional website by simply showing eg. MY SITE <[email protected]>, this way when people receive an email from my website, they can see MY SITE in their email preview list. Checking my config.inc.php I see the following related lines for FROM EMAIL: // Name of the site $site_name = "MY SITE"; // Site email address $site_email = "[email protected]"; // From address to use for mails sent using the contact form. // Set to $site_email to make it the same as the site email set above. $contactmail_from = $site_email; I am not a programmer but I would assume this is done here at the config.inc.php file. I tried replacing the site email to: $site_email = "SITE NAME <[email protected]>"; and the emails are now showing correctly in email previews, but now I am getting duplicated email in my [email protected] email for every email that is sent to users. Any idea how this is done properly in PHP? I appreciate your help in advance. Link to comment https://forums.phpfreaks.com/topic/167324-issue-with-from-email/ Share on other sites More sharing options...
Garethp Posted July 25, 2009 Share Posted July 25, 2009 Set the headers in the mail(); part of the code, like this $Header = "FROM: MYSITE <Email> \r\n"; $Header .= "Reply-To: Email"; mail($To, $Subject, $Message, $Headers); Also, this belongs in the main PHP Help forum, not the Regex Section Link to comment https://forums.phpfreaks.com/topic/167324-issue-with-from-email/#findComment-882616 Share on other sites More sharing options...
duxbox Posted July 26, 2009 Author Share Posted July 26, 2009 Garethp, Thanks for your response, This is the mail() portion of the POST.PHP file that sends out the email. can I not simply add the $site_name somewhere in there to get: SITE NAME <[email protected]> $subj = $lang['MAILSUBJECT_NEW_POST']; $subj = str_replace("{@ADTITLE}", $data['adtitle'], $subj); if (!@xmail($_POST['email'], $subj, $msg, $site_email, $langx['charset'])) Link to comment https://forums.phpfreaks.com/topic/167324-issue-with-from-email/#findComment-882997 Share on other sites More sharing options...
duxbox Posted July 28, 2009 Author Share Posted July 28, 2009 This is the mail code from another page called showad.php that has a form and sends the emails with full header like MY SITE <[email protected]> which I am trying to replicate for the activation emails. // Makeup mail headers and compose mime msg $mime_boundary = "<<<-=-=-[xzero.clfx.".md5(time())."]-=-=->>>"; $mailheaders = ""; $mailheaders .= "From: $contactmail_from\n"; $mailheaders .= "Reply-To: $_POST[email]\n"; $mailheaders .= "Date: " . date("r") . "\n"; $mailheaders .= "Message-ID: " . generateMessageID() . "\n"; if($_FILES['attach']['tmp_name'] && !$_FILES['attach']['error']) { $filename = $_FILES['attach']['name']; $filetmpname = $_FILES['attach']['tmp_name']; $filesize = $_FILES['attach']['size']; $filecontents = base64_encode(file_get_contents($filetmpname)); $fileencoding = "base64"; $dotpos = strrpos($filename, "."); if($dotpos !== FALSE) $ext = substr($filename, -$dotpos+1); if (in_array($ext, $contactmail_attach_wrongfiles)) { $mailerr = $lang['ERROR_INVALID_ATTACHMENT']; } elseif($filesize > $contactmail_attach_maxsize*1000) { $mailerr = "The attachment is too big"; } else { $mailheaders .= "MIME-Version: 1.0\n"; $mailheaders .= "Content-Type: multipart/mixed;\n"; $mailheaders .= " boundary=\"".$mime_boundary."\""; $fullmsg = ""; $fullmsg .= "This is a multi-part message in MIME format.\n"; $fullmsg .= "\r\n"; $fullmsg .= "--".$mime_boundary."\r\n"; $fullmsg .= "Content-Type: text/plain; charset=\"{$langx[charset]}\"\n"; $fullmsg .= "Content-Transfer-Encoding: 8bit\n"; $fullmsg .= "\r\n"; $fullmsg .= $mail; $fullmsg .= "\r\n"; $fullmsg .= "--".$mime_boundary."\r\n"; $fullmsg .= "Content-Type: application/octet-stream; name=\"".$filename."\"\n"; $fullmsg .= "Content-Transfer-Encoding: ".$fileencoding."\n"; $fullmsg .= "Content-Disposition: attachment; filename=\"".$filename."\"\n"; $fullmsg .= "\r\n"; $fullmsg .= $filecontents; $fullmsg .= "\r\n"; $fullmsg .= "--".$mime_boundary."--\r\n"; } } else { $mailheaders .= "Content-Type: text/plain; charset=\"{$langx[charset]}\"\n"; $mailheaders .= "Content-Transfer-Encoding: 8bit\n"; $fullmsg = $mail; } $mailheaders .= "\r\n"; if ($mailerr) { $mailresult = "n"; } else { if (mail($ad['email'], $lang['MAILSUBJECT_CONTACT_FORM'], $fullmsg, $mailheaders, "-f{$site_email}")) $mailresult = "y"; else $mailresult = "n"; } header("Location: $script_url/?$qs&mailed=$mailresult&mailerr=$mailerr"); exit; the page that I am working on which sends an activation link for each message or ad that users post on the site is called post.php and has the following email code: $subj = $lang['MAILSUBJECT_NEW_POST']; $subj = str_replace("{@ADTITLE}", $data['adtitle'], $subj); if (!@xmail($_POST['email'], $subj, $msg, $site_email, $langx['charset'])) Any idea? Thanks, Link to comment https://forums.phpfreaks.com/topic/167324-issue-with-from-email/#findComment-884589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.