Page 1 of 1

pear mail going to spam

Posted: Thu Mar 31, 2011 7:30 am
by dsjoes
The script below works but it goes straight to the junk folder only since i added the parts below to the form. (the form is in another file)
How do i stop it from going to the junk folder.
$error = $_GET['error'];
$httpagent = getenv ('HTTP_USER_AGENT');
$url = $_SERVER['HTTP_REFERER'];

Code: Select all

<?php
 require_once "Mail.php";
 	$optional = $_POST['optional'];
	$error = $_POST['error'];
	$url = $_POST['url'];
	$httpagent = $_POST['browser'];
	$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
 
 $from = "Web server <removed>";
 $to = "Admin <removed>";
 $subject = "Someone has submitted an error.";
 $body = "Someone has submitted an error.\n".
		"Error: $error\n".
		"URL: $url\n".
		"Web browser: $httpagent\n".
		"Anything else you want to add?: $optional\n".
		"IP: $ip\n";
 
 $host = "removed";
 $username = "removed";
 $password = "removed";
 
 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));
 
 $mail = $smtp->send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   header('Location: thank-you.html');
  }
 ?>

Re: pear mail going to spam

Posted: Sun Apr 03, 2011 4:06 pm
by dsjoes
does anyone know anything i can try?

Re: pear mail going to spam

Posted: Sun Apr 03, 2011 8:18 pm
by klandaika
The fact that it goes to spam has to do with how the reciepients email server/client categorizes the message.
The best thing you can do is configure the email server/client to trus the $from email that you are sending the message with.

You could also try making it into an HTML email and use table rows instead of new lines to put each peace of information.
Here is email code i use:

Code: Select all

function send($to, $subject, $text, $html, $cc = array(), $bcc = array()){
require_once('Mail.php');
require_once('Mail/mime.php');

$to = is_array($to) ? $to : explode(';', $to);
$cc = is_array($cc) ? $cc : explode(';', $cc);
$bcc = is_array($bcc) ? $bcc : explode(';', $bcc);

$hdrs = array(
			'From' => (empty($this->name) ? $this->email : $this->name." <".$this->email.">"),
			'To' => implode(', ', $to),
			'Subject' => $subject);

$mime = new Mail_mime();
$mime->setTXTBody($text);
$mime->setHTMLBody($html);

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$recipients = array_merge($to, $cc, $bcc);

$mail =& Mail::factory('smtp',
	  array ('host' => $this->server,
		'auth' => true,
		'username' => $this->username,
		'password' => $this->password));
$sendRes = @$mail->send($recipients, $hdrs, $body);

if (PEAR::isError($sendRes)) {
	trigger_error($sendRes->getMessage());
	return false;
}else{
	return true;
}
}