PDA

View Full Version : Fixed: SMTP PhpMailer


Zoidberg
02-20-2008, 04:47 PM
Download PhpMailer (http://sourceforge.net/projects/phpmailer) and install to the include/mail directory

change include/class.misc.php, function sendmail approx. Line 78 (http://www.osticket.com/forums/showpost.php?p=1638&postcount=8)
include(INCLUDE_DIR.'mail/mail.php');

create include/mail/mail.php

<?
require_once("class.phpmailer.php");

$mail = new phpmailer();

// $mail->Mailer = "mail"; // send via php
$mail->IsSMTP(); // send via SMTP
$mail->Mailer = "smtp";
$mail->Host = "smtp.yourwebhost.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentification
$mail->Username = "yourusername"; // SMTP username
$mail->Password = "yourpassword"; // SMTP password


$mail->From = "your@address.com";
$mail->FromName = $fromname;


$mail->AddAddress("$to");
$mail->AddReplyTo("$fromname", "$fromaddress");

// $mail->WordWrap = 50; // set word wrap
// $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
// $mail->AddAttachment("/tmp/image.jpg", "new.jpg");
// $mail->IsHTML(false); // send as HTML

$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($message);

// $mail->AltBody = "This is the text-only body";
$IsSent = 1;

if(!$mail->Send())
{
echo "email_has_not_been_sent <br><br>";
echo "Mailer Error: " . $mail->ErrorInfo;
$IsSent = 0;
exit;
}

?>

Enjoy.

F.B. ten Kate
02-22-2008, 05:43 AM
Like i state in the actual topic where i requested help i noticed two "bugs" which i think are rather easy to fix and would help alot of users, especially windows users.

1. The attachments DIR is not beeing stripped when retrieved from the database, meaning you can't just edit your attachments settings without having to edit the directory aswell. And as a side effect on windows systems won't upload attachments untill you double slash it at the moment. In our case our Database holds the value: "D:\\support\\scp\\files" and the Admin panel shows: "D:\support\scp\files" and if i'd update settings the database would turn into the previous string where as my admin panel would show: D:supportscpfiles. And ofcoarse the attachments scripts would be broken.

2. .TXT and .DOC aren't accepted because the file extention is case sensitive at the moment, which in my opinion isn't needed and only annoying for the user since he'd have to type all extentions twice! Just a simple .ToLower() function before checken the extension would be WIN!

Hope i didnt state things that people already knew ^^

Greetings,

F.B. ten Kate

jprost
02-25-2008, 04:32 AM
Download PhpMailer (http://sourceforge.net/projects/phpmailer) and install to the include/mail directory

change include/class.misc.php Line 78


create include/mail/mail.php


Enjoy.

what version was this for? In RC3 there is no line 78. I'm assuming that you are wanting it to go just after the sendmail() function (like around 59), and then to have all other lines within the function commented out.

thanx...
jason...

speedcoder
02-25-2008, 05:40 PM
change include/class.misc.php Line 78 is not to be found.....

speedcoder
02-25-2008, 05:55 PM
Can we fix this Thread?

The instructions above produce this error:

email_has_not_been_sent

Mailer Error: Language string failed to load: connect_host

jprost
02-25-2008, 06:18 PM
I got it working last night.

I can post my updates. I have to make some additional tweaks...however it works.

later...
jason...

4ice
02-25-2008, 06:38 PM
Can we fix this Thread?

The instructions above produce this error:

email_has_not_been_sent

Mailer Error: Language string failed to load: connect_host

Hi Speedcoder,

the problem is that this is an user provided fix. It's not done by osTicket.

Unfortunately the topic starter is probably not using the latest version or has made a mistake in his line numbering.

Edit: since Zoidberg has given more info, I removed the warning.

Zoidberg
02-25-2008, 10:04 PM
This works with RC3, but it should work with all other versions as well, because it implements email sending based on PHPmailer.

In class.misc.php set your function sendmail like this

/* Send email out after minor cleanups..*/
function sendmail($to, $subject, $message, $fromaddress,$fromname='', $xheaders = '') {
//TODO: Log all outgoing emails??

$eol="\n";
$fromname=$fromname?$fromname:$fromaddress;
//do some cleanup...avoid stupid errors.
$to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
$subject=preg_replace("/(\r\n|\r|\n)/s",'', trim($subject));
$message = preg_replace("/(\r\n|\r)/s", "\n", trim($message));

include(INCLUDE_DIR.'mail/mail.php');
}

Zoidberg
02-25-2008, 10:08 PM
Can we fix this Thread?

The instructions above produce this error:

email_has_not_been_sent

Mailer Error: Language string failed to load: connect_host

You'll need an email account that allows smtp access and a webhost that supports fsockopen(). In your mail.php adjust the lines

$mail->Host = "smtp.yourwebhost.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentification
$mail->Username = "yourusername"; // SMTP username
$mail->Password = "yourpassword"; // SMTP password

Careful: This is known not to work with hotmail email accounts as smtp servers, also your webhost has to support fsockopen(), which a lot of free providers simply don't

dfwgeek
03-03-2008, 10:24 PM
This worked for me. I have been having trouble sending automatic emails to users. I don't know why this is not built into osticket.

zolkir
03-04-2008, 12:40 PM
This fixed worked great for me, but I have a follow up question. Please forgive me, I'm a complete newbie to PHP.

I noticed at the end of the class.misc.php file, there are two different mail calls - what's the difference?

-- function sendmail($to, $subject, $message, $fromaddress,$fromname='', $xheaders = '')

-- mail($to,$subject,$message,trim($headers))

The reason I ask is because my email response is now working, but I'm still getting an error on the last mail call. Maybe I don't need it and was supposed to remove it - my include to mail.php is in between these two mail calls.

saaiber
03-04-2008, 05:04 PM
This doesn't want to work for me, always getting this error:

email_has_not_been_sent

Mailer Error: Language string failed to load: recipients_failed mail@domain.com where mail@domain.com is the mailaddress I'm trying to send a reply to.

This driving me crazy, no replies and no notification are sent out and my hostprovider says that php.ini is ok and fsockopen() is supported on the server.

What exactly needs to be set up in php.ini?

I have another host where osticket works like a charm without any error and in my other setup, neither the native php mailer setup, neither the fixed smtp solution works....

Nic

wvpw_mrw
04-02-2008, 06:17 PM
I was originally having problems getting the staff members to receive alerts that they had new tickets to work. Yes, the enable was selected for the department and manager.

I downloaded and installed the PhpMailer and created the mail.php file as noted in this thread. Here is the problem that I have now,

mail.php

$mail->From = "eticket@mydomain.org";
$mail->FromName = $fromname;

$mail->AddAddress("$to");
$mail->AddReplyTo("$fromname", "$fromaddress");

When someone repllies to a ticket to add information to their original ticket, it would reject the message with a 550 error due to unknown address. Plus, the message was being masked with an email address of "eticket@mydomain.org", but when you hit reply it would play this in the reply message to line:
"communications@mydomain.org" <ACME Communications Committee>

I was able to fix this by changing the mail.php code to:

$mail->From = $fromaddress;
$mail->FromName = $fromname;

$mail->AddAddress("$to");
$mail->AddReplyTo($fromaddress);

This results in the following in the to line of the reply message:
communications@mydomain.org

With this correction, and the addition of the mail.php & PhpMailer files, everything is working again.

Thank you for everyone's posts, it helped!!! :)

wvpw_mrw
04-03-2008, 07:04 PM
I guess I do have a question now, is there a way to make the mail.php file instead of using one account to send email through?

For example, I would like to use each departments accounts to send the email through my third party email server (this is becaue each user only gets 250 relays per day).

mail.php

$mail->IsSMTP(); // send via SMTP
$mail->Mailer = "smtp";
$mail->Host = "smtpout.mailserver.net"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentification
$mail->Username = "eticket@mydomain.org"; // SMTP username
$mail->Password = "GoofyPassword"; // SMTP password


I have 7 departments and all of them receive tickets that flow through the "eticket" account.

Any thoughts anyone?

michaelk
05-05-2008, 05:15 PM
I installed the PHPmail following the instructions, but still can't seem to find out why it is not sending the auto response.

I checked the PHP error log and nothing. Apache log, nothing. Does anyone have any tips of what to look for and where?

DiePlage
05-20-2008, 01:24 PM
just wanted to let you know thad Zoidbergs instructions worked well for me (1.6RC4 on CentOS 5). no flaws so far.

DiePlage

DiePlage
05-20-2008, 03:42 PM
Unfortunately I was a bit quick.
Allthough all emails seem to be sent just fine, I am receiving the following error all the time:
email_has_not_been_sent <br><br>Mailer Error: Language string failed to load: connect_host

The above instructions don't seem to fit as I don't have any mails NOT being sent correctly.

Any hint would be greatly appreciated.

Thanx in advance!


just wanted to let you know thad Zoidbergs instructions worked well for me (1.6RC4 on CentOS 5). no flaws so far.

DiePlage

mhinemallow
05-27-2008, 11:04 PM
i tried using Zoidbergs instructions, but whenever someone make a new ticket or a reply to a ticket, they can only see white screen.. does anyone have ideas on what to do? please..

PowerSurge
06-09-2008, 07:18 AM
I'm having the same problem as mhinemallow.

The ticket is created and an email is sent alright but they just get dumped to a blank page. Any ideas?

redcap
06-18-2008, 12:38 AM
If you want to send UTF-8 emails, for example something written in Japanese, then you need to make the following changes to mail.php:

I inserted this after the $mail->IsSMTP(); line.
$mail->CharSet = "UTF-8";
$mail->Encoding = "8bit";

In addition, you need to change the lines that read:

$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($message);

to

$mail->Subject = $subject;
$mail->Body = $message;

As the utf_decode changes utf-8 formatted text into ISO-8859-1, it will garble non-Ascii based character sets such as Japanese or Chinese.

I think this solution relies on your mail host being able to handle 8-bit email encoding, which it should unless you really don't like updating.

vendejp
06-19-2008, 02:58 PM
I think this is a bug in phpMailer v2.1

If you look at your apache log youll probably see something like:

[Thu Jun 19 13:46:08 2008] [error] [client 71.236.67.224] PHP Fatal error: Multiple access type modifiers are not allowed in /var/www/html/support/include/class.pop3.php on line 318, referer: http://domain.com/support/scp/profile.php?t=pref

For me, class.pop3.php was overwritten by the new one in phpMailer_v2.1.zip.

If you go to this line, I found that the method:

public private function getResponse ($size = 128) {
$pop3_response = fgets($this->pop_conn, $size);

return $pop3_response;
}



changing it to the following seemed to fix it for me thus far:

private function getResponse ($size = 128) {
$pop3_response = fgets($this->pop_conn, $size);

return $pop3_response;
}


If this is not the case, check your apache log anyway, it should be dumping an error


I'm having the same problem as mhinemallow.

The ticket is created and an email is sent alright but they just get dumped to a blank page. Any ideas?

vendejp
06-19-2008, 03:06 PM
actually, this is already an open bug for phpMailer

http://sourceforge.net/tracker/index.php?func=detail&aid=1991592&group_id=26031&atid=385707

s0lid
07-13-2008, 07:13 PM
I installed the PHPmail following the instructions, but still can't seem to find out why it is not sending the auto response.

I checked the PHP error log and nothing. Apache log, nothing. Does anyone have any tips of what to look for and where?

im having the same problem. My replies all sending fine. But my alerts and no reply email seems still connected to my servers sendmail. How can i config it to use mail.php instead?

Thanks!

DiePlage
07-14-2008, 03:13 AM
If you are running on linux, just forget about phpmailer.
I spent days with phpmailer and similar scripts. After that I just installed postfix and konfigured it within 10 minutes. Thata way osticket doesn't have to care about how to get emails out, it just passes them to the OS.

kronos5150
09-03-2008, 08:18 PM
Thanks for the help with this. It worked great. All I had to do is modify smtp settings to my enviroment and it was working great.

rubulcheir
09-26-2008, 03:20 AM
i tried using Zoidbergs instructions, but whenever someone make a new ticket or a reply to a ticket, they can only see white screen.. does anyone have ideas on what to do? please..

I made Zoidberg's mods to my installation of osticket 1.6rc4 and experienced this problem as well. It was due to the fact that the PHPMailer class was being declared twice because in (his) mods the inclusion of mail.php is inside osticket's sendmail() function in includes/class.misc.php- which (assuming you have notifications to Admin and/or staff turned on in osticket) is called multiple times on submission of a new ticket or message (i.e. once to send the autoresponder to the submitting client, and then additionally, one or more times to the configured notification receivers).

To fix this:

In mail.php, comment out the include for PHPMailer: ~line ? (depends on your script):

//include("class.phpmailer.php");

You might also destroy the $mail object after the script terminates successfully. At the bottom of the script after:

if(!$mail->Send())
{
//echo $to."<br>";
//echo "email_has_not_been_sent <br><br>";
echo "" . $mail->From . "<br />";
echo "Mailer Error: " . $mail->ErrorInfo;
$IsSent = 0;
//exit();
}

Add:

unset($mail);

Next, in include/class.misc.php:

At the top, just BEFORE:

class Misc { declaration (~line 18),

Add:

include("mail/class.phpmailer.php");

That should fix the issue. As a fallback I also modified the sendmail() function in include/class.misc.php so that it will first attempt to send via SMTP with PHPMailer, and if that fails, revert back to using the standard PHP mail() function:

~ line 57 (1.6rc4):

/* Send email out after minor cleanups..*/
function sendmail($to, $subject, $message, $fromaddress,$fromname='', $xheaders = '') {
//TODO: Log all outgoing emails??

$eol="\n";
$addparam = "-fyourknownaddress@yourdomain.ext";
$fromname=$fromname?$fromname:$fromaddress;
//do some cleanup...avoid stupid errors.

$to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
$subject=preg_replace("/(\r\n|\r|\n)/s",'', trim($subject));
$message = preg_replace("/(\r\n|\r)/s", "\n", trim($message));

/* First attempt send via SMTP with PHPMailer */
include(INCLUDE_DIR.'mail/mail.php');
if(!$IsSent == 1) {//failed...now attempt using PHP mail();

#Headers
$headers .= "From: ".$fromaddress.$eol;
$headers .= "Reply-To: ".$fromaddress.$eol;
$headers .= "Return-Path: ".$fromaddress.$eol;
$headers .= "Message-ID: ".time()."-".$fromaddress.$eol;
$headers .= "X-Mailer: MyMailer v x.xx".$eol;
if($xheaders) { //possibly attachments...does mess with content type
$headers .= $xheaders;
}else{
$headers .= "Content-Type: text/plain; charset=utf-8".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol;
}
@mail($to,$subject,$message,trim($headers),$addpar am);
}
}

Note: The $addparam (optional) forces the envelope_from for the message to be set to the specified address with the -f sendmail flag. Nobody likes email from 'nobody'! The address specified after -f MUST be valid.

**For some reason in the preview of this post the line:
@mail($to,$subject,$message,trim($headers),$addpar am); is displaying a space that shouldn't be there... ?? Make sure there is no space in the variable name $addparam in your code!

See: http://au2.php.net/function.mail beneath 'additional_parameters (optional)'.

Osticket is great - I hope the above assists some other users!

BTW - This was done using PHPMailer v. 2.2.1. Osticket install on Linux/PHP 5.23/Apache 2.2.9 & cPanel

fourwheeldrifter
10-09-2008, 01:27 PM
This works with RC3, but it should work with all other versions as well, because it implements email sending based on PHPmailer.

In class.misc.php set your function sendmail like this

/* Send email out after minor cleanups..*/
function sendmail($to, $subject, $message, $fromaddress,$fromname='', $xheaders = '') {
//TODO: Log all outgoing emails??

$eol="\n";
$fromname=$fromname?$fromname:$fromaddress;
//do some cleanup...avoid stupid errors.
$to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
$subject=preg_replace("/(\r\n|\r|\n)/s",'', trim($subject));
$message = preg_replace("/(\r\n|\r)/s", "\n", trim($message));

include(INCLUDE_DIR.'mail/mail.php');
}


i can confirm that this fixes the issue with RC4 of not sending emails to staff members but still sending to customers

thanks to the coder that worked this out :)

jordanroth
03-09-2009, 06:42 PM
1. Is osTicket still in development?
2. Can a feature be added in the next release to resolve this issue?
3. When could we expect that next release?

werdnags
07-15-2009, 03:00 PM
I have just installed OSTickets but having a problem trying to use the amendments mentioned in this thread. I am trying to use authenticated SMTP to send emails. When I open my class.misc.php file I do not have the code for the sendmail function so I can't change it.

Anyone any ideas?

Thanks.