pear mail going to spam

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

pear mail going to spam

Post 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');
  }
 ?>
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: pear mail going to spam

Post by dsjoes »

does anyone know anything i can try?
klandaika
Forum Newbie
Posts: 19
Joined: Wed Mar 30, 2011 3:25 pm
Location: New York

Re: pear mail going to spam

Post 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;
}
}
Post Reply