Reputation: 4042
I've been thinking, and I have question regarding multiple e-mail addresses and the mail function.
Is it possible to have PHP send an email to a particular smtp
server; for instance if I have two addresses.
Configuration
smtp.fakecompany1.co.nz
Intended Recipient
[email protected]
(smtp.fakecompany1.co.nz
)[email protected]
(smtp.fakecompany2.com
)Currently, if the smtp
of the intended recipient
(smtp.fakecompany1.co.nz) is setup then that recipient
from the intended smtp
(smtp.fakecompany1.co.nz) will receive e-mail; but my question is in regards to whether it could be possible to select an smtp
(smtp.fakecompany1.co.nz) and send an email, without requiring to authenticate into a DIFFERENT smtp
(smtp.fakecompany2.com).
(source: iforce.co.nz)
TL;DR can I send an email from smtp.fakecompany1.co.nz
to smtp.fakecompany2.com
(given the email exists on both servers), without modifying the authentication details on the primary server (Due to technical issues with Gmail).
Upvotes: 1
Views: 53
Reputation: 13432
You can SMTP with PEAR::Mail instead of using mail()
. See this question for an example: how to use php pear mail
Here is a modified example I copied from the linked Q:
require_once "Mail.php";
$from = "<[email protected]>";
$to = "<[email protected]>";
$subject = "Hi!";
$body = "Hello world";
$host = "smtp.fakecompany2.com";
$port = "465";
$username = "<[email protected]>";
$password = "testtest";
if (YOUR HEADER CHECK HERE) {
$host = "smtp.fakecompany1.co.nz";
}
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
Upvotes: 1