Sent SMTP mail arrives via PHP mail

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Sent SMTP mail arrives via PHP mail

Post by RonP » 2020-11-14 15:16

Hi,
In spite of setting the SMTP parameters I still get, every now and then, a mail send by PHP.
(every now and then .... in very random times)

My provider urged me to step over to SMTP so I did however....didn't help that much.
Any solution to be think of?

I use AppGini V05R84
Set code in config.php file

Code: Select all

'mail_function' => "smtp",
'smtp_server' => "smtp.mail.pcextreme.nl",
'smtp_encryption' => "tls",
'smtp_port' => "587"

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by RonP » 2020-12-13 10:42

Hi There,

The problem still occurs, I can see in the php-mail.log that the mail still is send by PHP-mail and not by SMTP.
What can I do to have the mails sent by SMPT?

Ron

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by jsetzer » 2020-12-13 18:16

Please check: are you calling the appgini built-in sendmail($mail) function or the php mail() function?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by RonP » 2020-12-14 15:25

Hi JSetzer,
Thanks for the reply.
It is not clear for me:
  • Where do I call the mailfunction? Is this in one of the "Hooks files"?
  • Is the mailfunction to be called within file: incFunctions.php?
If so, I've found:

In hooks file: contacten.php (a mail should be sent:
function contacten_after_insert($data, $memberInfo, &$args {
function contacten_before_update(&$data, $memberInfo, &$args) {
function contacten_before_delete($selectedID, &$skipChecks, $memberInfo, &$args) {
@mail(
// mail recipient
"{$data['Email']},[email protected]",

// subject
"Heiloo Energie-Leden:{$data['Voornaam']} - {$data['Achternaam']} heeft zich als nieuw lid aangemeld",

// message
"Nieuwe inschrijving ingevoerd door:{$memberInfo['username']} \n\n".
$messageData,

// sender address
"From: [email protected]"
);
Ron

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by jsetzer » 2020-12-14 15:54

If you want to send emails using SMTP, configured in admin area, you will have to use the AppGini built-in sendmail($mail)-function and not the default PHP mail-function, I think.

See here:
viewtopic.php?t=2555#p8318
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by jsetzer » 2020-12-14 16:00

It is fine to call sendmail(...) from within a hook function.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by RonP » 2020-12-15 11:21

Hi JSetzer,
I've done that before, however.... nope
Attachments
SMTP.PNG
SMTP.PNG (48.81 KiB) Viewed 2928 times

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by onoehring » 2020-12-18 10:48

Hi,

strange.
Did you try to force executing the sendmail for tests? What happens - nothing?
I would suggest you check your config.php file where the SMTP settings are saved. Are they correct? Maybe even try to create a new email account in your mail program and copy&paste the credentials from the config.php. Can you send mails?
I myself had a strange experience yesterday: A university IMAP account worked - the SMTP with the same credentials did not ... so strange things happen.

PS: I have created a helper function (see below) which essentially is the sendmail "a little easier to use".

Code: Select all

function myMail ($username, $email, $mailSubject, $mailMessage){
	$mail_status = sendmail(array(
		'to' => $email,
		'name' => $username,
		'subject' =>  $mailSubject,
		'message' => $mailMessage
	)); 
	
	return $mail_status;
}
Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by jsetzer » 2020-12-18 13:16

@Ron and @others:
Maybe this structured step-by-step guide which I have written today can help:
https://appgini.bizzworxx.de/appgini/st ... ing-mails/

@Olaf:
Wrapping the built-in sendmail($mail) function is a very nice idea for beginners! Well done!
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by RonP » 2020-12-21 14:07

Hi JSetzer and Olaf,
Thanks for the "tips".
Especially the "Step-by-Step article"

As my PHP is very poor I now wonder how I can the formerly used "PHP mail" parameters effective in the SMTP mail.

Code: Select all

@mail(
// mail recipient
"{$data['Email']},[email protected]",

// subject
"Heiloo Energie-Leden:{$data['Voornaam']} - {$data['Achternaam']} heeft zich als nieuw lid aangemeld",

// message
"Nieuwe inschrijving ingevoerd door:{$memberInfo['username']} \n\n".
$messageData,

// sender address
"From: [email protected]"
);
So, in the Subject I like to see back:
"Heiloo Energie-Leden:{$data['Voornaam']} - {$data['Achternaam']} heeft zich als nieuw lid aangemeld",
And in the Message:
"Nieuwe inschrijving ingevoerd door:{$memberInfo['username']} \n\n".
And what I've read:
No CC/BCC are allowed, however "the manger" should receive a copy of a send message.
How can I fix this all?
Ron

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by jsetzer » 2020-12-21 14:20

@Ron: You are still using mail-command, but, as mentioned before, you have to use sendmail command if you want AppGini to send you mails using the SMTP parameters you have configured.

Please follow the step-by-step guide. I think everything you need has been described there, especially testing your SMTP parameters and using sendmail command in PHP.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Sent SMTP mail arrives via PHP mail

Post by RonP » 2020-12-21 15:28

Jsetzer,
I've followed the Step-by-Step Quide, and all that works well.

Code: Select all

$mail = [
    "to" => "{$data['Email']}",
    "name" => "Verzonden door: {$memberInfo['username']}",
    "message" => "$messageData",
    "subject" => "Ledenadministratie: {$data['Voornaam']} {$data['Achternaam']} heeft een wijziging uitgevoerd",
    "debug" => 4
];
I'm ashamed that I didn't look more precise.
Now I see that it works.

However: How to get a CC/BCC send?
Again sorry for the former post.
Thank you so much
Ron

Post Reply