Solved

PHP Web App not sending e-mails to external domain

Posted on 2013-02-01
3
282 Views
Last Modified: 2013-02-04
Hi,

I have a PHP Helpdesk web app installed on our Intranet server. Part of the job of the Helpdesk is to send e-mails to Users to keep them up to date with calls. The setup is quite simple and you have to enter an SMTP address into the call in order to send these updates.

We have two domains. The SMTP Server (Exchange 2010) is a different server to the web app server, which is running IIS.

When a call is added/updated and the e-mail address of the User is on the same domain the e-mail works OK. But when we're trying to send to the other domain (for which mail must go out before it comes into the second domain) it fails to be relayed.

i.e. joe.bloggs@samedomain.com works, but joe.bloggs@otherdomain.com does not.

I don't know how to set up PHP Mail and have no idea if it would break things anyway.

I know that the web server can send SMTP to joe.bloggs@otherdomain.com because an ASPX page that sends out passwords works OK to that domain.

I've looked around, but I can't figure out where the issue may lie! :(
0
Comment
Question by:winstalla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:mcnute
ID: 38844313
Why don't you simply take the working code out of the aspx page which sends the password to build the php Mail function for your other page?
0
 

Author Comment

by:winstalla
ID: 38850297
The SMTP for the ASPX page is set in the web.config file with the following details:
      <smtp deliveryMethod="Network" from="webmaster@mydomain.com">
        <network host="mailserver.domain.local" port="25"/>

Open in new window

but I have no idea how to replicate this within PHP. I have looked, briefly, at the PHP.ini file, but changes made to this file do not seem to have helped. Is it here that I should be looking?
0
 
LVL 11

Accepted Solution

by:
mcnute earned 500 total points
ID: 38850316
After you make changes to your php.ini a restart of your webserver (apache, iis, ngnx) is necessary for changes to be effective.

In php you would do it like this:
<?php
 require_once "Mail.php";
 
 $from = "Sandra Sender <sender@example.com>";
 $to = "Ramona Recipient <recipient@example.com>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 
 $host = "mail.example.com";
 $username = "smtp_username";
 $password = "smtp_password";
 
 $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 {
   echo("<p>Message successfully sent!</p>");
  }
 ?>

Open in new window


This is done with the pear package Mail which is installed by default in many cases and almost for sure in any php5 installation.

If you do not have this installed, then consider swiftmailer, which is a powerful mail class which doesn't need complicated installation. You just download it, put it in a webfolder of your choice and reference to it in a require_once() function accordingly.

With swiftmailer you would do something like this:
require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password')
  ;

/*
You could alternatively use a different transport such as Sendmail or Mail:

// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

// Mail
$transport = Swift_MailTransport::newInstance();
*/

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
In-place Upgrading Dirsync to Azure AD Connect
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question