View Full Version : sending mail from a different server
harlequin2k5
09-11-2007, 02:31 PM
I think that's what I mean...
the site I'm working on is being hosted by godaddy but it's been decided that if possible, form mail should be sent through our server (at some point all of the sites are going to be transferred from godaddy to our servers)
I'm sure it requires a function and I've looked through both of my books regarding mail() and didn't find anything about pointing to a server and I'm not sure how to pose the question for google
any help is greatly appreciated!
CFMaBiSmAd
09-11-2007, 03:07 PM
Do you want received email for the domains hosted at godaddy to go to your mail server (in which case you need to change the DNS MX record) or do you just want form email to get sent through your mail server?
To get PHP to send email to/through your mail server, you need to set the "SMTP" setting to point to your mail server. This can be done in a .htaccess file or in the script using an ini_set() statement.
However, there are a several conditions that must be met in order for this to work.
If the the To: address is a mail box on your mail server, your server will likely accept an email from a php script and place it into the mail box. If it does not, then you will need to use SMTP authentication against a mail box on your mail server.
If the To: address is not a mail box on your mail server, your mail server may accept the email if the From: address is a mail box on your mail server. If it does not, then you will need to use SMTP authentication against a mail box on your mail server.
If both the To: and From: address are not for a mail box on your mail server, I can guarantee that your mail server will not accept the email. In which case you will need to use SMTP authentication against a mail box on your mail server.
The PHP mail() function does not support SMTP authentication. You would need to use something like the phpmailer class to use SMTP authentication. The good news is, once you switch to using something like the phpmailer class, you can keep using it under all possible server configurations, just by changing settings.
To get other email servers to accept mail from your server, where the domain in the From: address does not match the domain of your mail server, you will need to add an SPF record to the DNS server for the domain in the From: address that says your email server is authorized to send email for that domain.
harlequin2k5
09-11-2007, 03:23 PM
wow! I was not expecting such a detailed response!
the thing that's making me crazy is this is the first site in a series and trying to decide what needs to go into the template - I'm hoping by the time I have this site finished that it will have already been moved from godaddy to our server anyway
based on your response about the phpmailer class - is it advisable to employ this? is it something worth adding to the template? and if so, where would I begin my googling for tutorials?
thank you so much CFMaBiSmAd
CFMaBiSmAd
09-11-2007, 03:45 PM
You can switch to use a mailer class now with the existing mail server. Then to test using your mail server, just change settings. If it does not work, just change the settings back while you figure out what the problem is.
A number of people have mentioned the Swift mailer class, I have include a link to it as well -
http://phpmailer.sourceforge.net/
http://www.swiftmailer.org/
harlequin2k5
09-11-2007, 04:13 PM
fantastic!
I had found the phpmailer and I'm in the process of trying to set it up
this is new territory for me and I'm quite excited about it *chuckles*
and to continue to ask stupid questions...although all the code and variables appear a bit intimidating right now - this will work just fine for form submission right? and I can still submit the data from the form to the db at the same time?
thanks ever so much CF!!
edit: and are you going to be ready to help me when I ready to start with dynamic rss feeds? lol j/k
harlequin2k5
09-14-2007, 06:31 PM
after doing another 2 days worth of research and encountering numerous other errors while trying to use swiftmailer (some had nothing to do with the code - there were several smtp clients installed on the server that created quite a problem) - I finally found a php5 version of phpmailer
the error I'm receiving is:
Fatal error: Cannot access self:: when no class scope is active in /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/newmail.php on line 20
line 20 is
$mail = new PHPMailer();
this is the php for newmail.php:
<?php
require("includes/mailer/class.phpmailer.php");
$name=Trim($_POST['name']);
$company=Trim($_POST['company']);
$title=Trim($_POST['title']);
$contacttype=Trim($_POST['contacttype']);
$phone=Trim($_POST['phone']);
$email=Trim($_POST['email']);
$timetoreach=Trim($_POST['timetoreach']);
$timezone=Trim($_POST['timezone']);
$region=Trim($_POST['region']);
$pricerange=Trim($_POST['pricerange']);
$propertytype=Trim($_POST['propertytype']);
$timeframe=Trim($_POST['timeframe']);
$updates=Trim($_POST['updates']);
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "67.78.206.210"; // SMTP server
$mail->From = $email;
$mail->AddAddress("info@shoppingcenter-advisor.com");
$mail->Subject = "Message received from Shopping Center Advisor";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->Body .="Message sent from more information form:\n";
$mail->Body .="$name\n";
$mail->Body .="$company\n";
$mail->Body .="$title\n";
$mail->Body .="$contacttype\n";
$mail->Body .="$phone\n";
$mail->Body .="$email\n";
$mail->Body .="$timetoreach\n";
$mail->Body .="$timezone\n";
$mail->Body .="$region\n";
$mail->Body .="$pricerange\n";
$mail->Body .="$propertytype\n";
$mail->Body .="$timeframe\n";
$mail->Body .="Would like to receive updates: $updates\n";
$mail->WordWrap = 50;
if(!$mail->Send())
{
//print "<meta http-equiv=\"refresh\" content=\"30;URL=no.php\">";
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
/* if ($success)
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=yes.php\">";
}
else
{
print "<meta http-equiv=\"refresh\" content=\"30;URL=no.php\">";
} */
}
else
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.php\">";
echo 'Message has been sent.';
}
?>
the 2 files within phpmailer are class.phpmailer.php and class.smtp.php
I'm getting so much closer...any thoughts on this new error?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.