Add Name & email in CEmail Object

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
kirondedshem
User
Posts: 642

Add Name & email in CEmail Object

Post by kirondedshem »

I have been using the cEmail object to send emails programatically like this, ut for example If my email is my_email@mail.com and I am called John Doe. I always see other emails refering to me by name.
To achive this I can use default phpmailer functionality library like below.

$mail = new PHPMailer;
//add sender's email and names
$mail->setFrom('my_mail@mail.com','Sender Full Names');
//add a reciepient and thier names
$mail->setFrom('some_mail@mail.com','Recipients Full Names');

And on sending this mail I always see the names.

BUT in phpmakers versio of cEmail, I can only add a reciepients email, I cant add it with his names, eg

$Email = new cEmail;
$Email->AddRecipient("kirondedshem@gmail.com");

When I send emails I can only see each entity refered by email, so How can I add arecepient email and names into this object like the way you seee it in phpmailer


mobhar
User
Posts: 11703

Post by mobhar »

Have you tried this?

$Email->AddRecipient("Recipient Full Name kirondedshem@gmail.com");


kirondedshem
User
Posts: 642

Post by kirondedshem »

Thnaks, Ive tried it but it still wont accept it, Infact Ive tested multiple variation of that and found the emails will only send if the receipient you are adding is PURELY the email address, if I try to even enclose it in "<>" brackets it still wont accept it.
Am looking at thier function in phpfn14.php and still cant see any traces of any of the fucntions accepting a name and email


arbei
User
Posts: 9355

Post by arbei »

You need to update the function ew_SendEmail() in phpfn14.php in order to handle the recipient email address with name.

With reference the code to add the sender, you can update the code as below.

From :
...
foreach ($arrTo as $sTo) {
$mail->AddAddress(trim($sTo));
}
...

To :
...
foreach ($arrTo as $sTo) {
if (preg_match('/.+<([\w.%+-]+@[\w.-]+\.[A-Z]{2,6})>$/i', trim($sTo), $m)) {
$mail->AddAddress($m[2], trim($m[1]);
} else {
$mail->AddAddress(trim($sTo));
}
}
...


kirondedshem
User
Posts: 642

Post by kirondedshem »

Thank for the hint, but since I dont want to change thier template to edit the phpfn file, I'll just use the phpmailer library directly untill they fix it. Thanks again


mobhar
User
Posts: 11703

Post by mobhar »

kirondedshem wrote:
but since I dont want to change thier template to edit the phpfn file

You may simply clone the ew_SendEmail() function, customize it just like arbei mentioned, and then put the customized version (let's say the clone version is "my_SendEmail()" function) in "Global Code" section, afterwards just call it from any server event that suits your needs.


kirondedshem
User
Posts: 642

Post by kirondedshem »

ok, i think Ill give it a try and get back here


Post Reply