GAE php mail function question

108 views
Skip to first unread message

Jukka Hautakorpi

unread,
Jul 18, 2017, 3:38:25 AM7/18/17
to Google App Engine
I have weird problem with my gae php application

i checked the code and noticed that one of the email-sending pages was using php mail and not googles's new Message() - method.
But it did work somehow, i can't understand why because i read the docs year or 2 ago that mail -function is not in use.
Now i changed it to new Message() -method but the email gets parsed as text and my html tags are visible in the thunderbird when i receive the mail.
Also i did not find anymore the new Message() documentation from google's site

1. is mail() now actually supported ?
2. how do i get html mail

runtime: php55

this is the code that makes tags visible:

require_once 'google/appengine/api/mail/Message.php';
use \google\appengine\api\mail\Message;

$daterand=date("Y-m-d").' '.rand(1000,9999);
$subject = "New mail - $daterand";

$eol="\n";
$Momentn = mktime().".".md5(rand(1000,9999));
$Servername = ereg_replace("www.","",$_SERVER["SERVER_NAME"]);
if(strlen($Servername)<2)$Servername = "PHPMAILSERVER";

$headers= 'To: '.$email;
$headers.=$eol;
$body = "welcome to the app!<br />";
$body.="\r\nLinks and stuff, thanks!</i><br />";


//$headers= 'To: '.$my_email; //not allowed 2013

$headers      .= 'From: '.$sender_email.$eol; //ei itseä ! google ei tykkää
//GAE DOES NOT ACCEPT: $headers      .= "Message-ID: <".$Momentn."@".$Servername.">".$eol;
//GAE DOES NOT ACCEPT: $headers      .= 'Date: '.date("r").$eol;
$headers .= "Content-Type: text/html; charset=UTF-8".$eol;
//GAE DOES NOT ACCEPT:$headers .= "MIME-Version: 1.0\n";
//GAE DOES NOT ACCEPT:$headers .= "Content-transfer-encoding: 7bit\n";
//$mailresult=mail('', $subject, $body, $headers);

if($appengine) {
//use \google\appengine\api\mail\Message;

$body = '<html><body>'.$body.'</body></html>';
try
{
  $message = new Message();
  $message->setSender($sender_email);
  $message->addTo($email);
  $message->setSubject($subject);
  $message->setTextBody($body);
  $message->send();
  $mailresult=true;
} catch (InvalidArgumentException $e) {
  $mailresult=false;
}


Jukka Hautakorpi

unread,
Jul 18, 2017, 4:11:37 AM7/18/17
to Google App Engine
Problem PARTLY resolved by changing $message->setTextBody($body); to $message->setHtmlBody($body) bu 
But this does not explain the weirdness that all the other files & functions that work exactly like that  in the example does work beautiful html messages even tough there is no setHtmlBody 
and i still need question does the mail() function work or did i misunderstood..

part of sourcecode of setTextBody -message that is still html:

X-Google-Appengine-App-Id: e~xxxxx
X
-Google-Appengine-App-Id-Alias: xxxxxxx
X
-Backend-Scan: 1
Message-ID: <f403045ec682cb16a9055491abac@google.com>
Subject: =?UTF-8?Q?Tuunix_Ajop=C3=A4iv=C3=A4kirja=2C_uusi_salasana_=2D_2017=2D07=2D18_4?=
       
=?UTF-8?Q?650?=
From: tuunix@tuunix.fi
To: jukka@tuunix.fi
Content-Type: multipart/alternative; boundary="f403045ec682cb1688055491aba9"
X
-Spam-Status: No, score=-1.9 required=15.0 tests=BAYES_00,
        HEADER_FROM_DIFFERENT_DOMAINS
,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,
        RCVD_IN_MSPIKE_H3
,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD,SPF_PASS,URIBL_BLOCKED
        autolearn
=ham autolearn_force=no version=3.4.0
X
-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mailgw1.xx.fi
X
-Virus-Scanned: clamav-milter 0.99.2 at mailgw1.xx.fi
X
-Virus-Status: Clean

--f403045ec682cb1688055491aba9
Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes
Content-Transfer-Encoding: base64

VGVydmV0dWxvYSBrw6R5dHTDpG3DpMOkbiBUdXVuaXggYWpvcMOkaXbDpGtpcmphYSENClNpbnVs
bGUgb24gbHVvdHUgdXVzaSBzYWxhc2FuYS4NClZvaXQga2lyamF1dHVhIG9zb2l0dGVlc3NhIGh0
dHA6Ly90dXVuaXhham9wYWl2YWtpcmphLmFwcHNwb3QuY29tIEF2YWEgIA0KQWpvcMOkaXbDpGtp
cmphIHTDpHN0w6QNCg0KU2FsYXNhbmFzaSBvbiBzaXJlZW5pNjc1DQoNCg0KTWlrw6RsaSBldCBv
bGUga3V1bGx1dGthYW4gbW9pc2VzdGEgcGFsdmVsdXN0YSBqYSBlcMOkaWxldCBldHTDpCB2aWVz
dGkgdHVsaSAgDQp2w6TDpHLDpMOkbiBvc29pdHRlZXNlZW4sIHbDpGxpdMOkIHTDpG3DpCB2aWVz
dGkgb3NvaXR0ZWVzZWVuIHR1dW5peEB0dXVuaXguZmksICANCktpaXRvcyENCg
==
--f403045ec682cb1688055491aba9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Tervetuloa k=C3=A4ytt=C3=A4m=C3=A4=C3=A4n Tuunix ajop=C3=A4iv=C3=A4kirjaa!<=
br
/>
Sinulle on luotu uusi salasana.<br />Voit kirjautua osoitteessa http://tuun=
ixajopaivakirja
.appspot.com  <a href=3D"http://tuunixajopaivakirja.appspot.=
com/"
>Avaa Ajop=C3=A4iv=C3=A4kirja t=C3=A4st=C3=A4</a><br /><br />Salasanas=
i on xxxxxxxxxxx
<br /><br />
                       
<br /><i>Mik=C3=A4li et ole kuullutkaan moisesta palvelusta ja ep=C3=A4i=
let ett
=C3=A4 viesti tuli v=C3=A4=C3=A4r=C3=A4=C3=A4n osoitteeseen, v=C3=A4=
lit
=C3=A4 t=C3=A4m=C3=A4 viesti osoitteeseen tuunix@tuunix.fi, Kiitos!</i><=
br
/>
--f403045ec682cb1688055491aba9--


Jordan (Cloud Platform Support)

unread,
Jul 18, 2017, 3:27:51 PM7/18/17
to Google App Engine
Google Groups is meant for general product discussions and not for technical support or for reporting issues. It is recommended to post your technical questions to Stack Overflow using the supported Google Cloud tags. Any issue or feature requests you would like to report should be filed in the appropriate Public Issue Tracker. 

Jukka Hautakorpi

unread,
Jul 19, 2017, 5:44:24 AM7/19/17
to Google App Engine
Ok, thanks

I also noticed a weird bug in my code, the $headers - variable is not even used in the GAE message sending
i tought that it was in use and tried to alter it.
Reply all
Reply to author
Forward
0 new messages