email shows # as %40 - php

I am working on Yii and I need to send a confirmation email one sign up. The content shows the email as abc%40#example.com
the email is directly called from the database and added to the mail function
I am not sure how this can be fixed
$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $registerform->activkey, "email" => $registerform->email));
the above code is the sample
Any help is appreciated
Apologies
the result is shown like this abc%40example.com and not abc%40#example.com

Try this:
$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $registerform->activkey, "email" => urldecode($registerform->email)));

Related

Email attachment uses the wrong file extension

I am working on some code that will create an iCalendar and then send an Outlook email with an ics file of the created event, it works as intended but there is one problem.
When the email gets sent, the attachment is given the wrong name (ATT00001.bin instead of Meeting.ics) and it isn't sent as a .ics but as a .bin. The contents of the file are still just as they are supposed to be.
Any help is appreciated, thanks!
use Spatie\IcalendarGenerator\Components\Calendar;
use Spatie\IcalendarGenerator\Components\Event;
...
$calendar = Calendar::create('Company test meeting')
->event(Event::create()
->name('Company test meeting')
->description('A test meeting about Company')
->startsAt(new \DateTime('24-03-2022 10:00'))
->endsAt(new \DateTime('24-03-2022 11:30'))
)->get();
$mailer = new Mailer('default');
$mailer->setAttachments([
'Meeting.ics' => [
'data' => $calendar,
'contentDisposition' => false
]
]);
$mailer->setFrom(['replacement#outlook.com' => 'CompanyName'])
->setTo('replacement#outlook.com')
->setSubject('Company meeting')
->deliver('Hey there I would like to have a meeting about Company');
So I figured it out.
When I was making the email, I was using the cakephp 4 cookbook.
There it said that: "The mimetype and contentId are optional in this form." and I made the mistake of just assuming that I didn't need it.
The mimetype for a ics file is text/calendar so I just added this to my setAttachments like this:
$mailer = new Mailer('default');
$mailer->setAttachments([
'Meeting.ics' => [
'data' => $ical,
'mimetype' => 'text/calendar', //I added the mimetype here
'contentDisposition' => false
]
]);
$mailer->setFrom(['private#outlook.com' => 'Company'])
->setTo('private#outlook.com')
->setSubject('Companymeeting')
->deliver("Dummy text " . $attendee . " About " . $description . "");
$this->set('calendar', $ical);
I'm still working on how to get the right filename but that isn't as important as the file extension. But if anybody knows, I would love to know.

Moodle Enrolment Email for Teachers - Add Student Email Address

I'm running Moodle, and have a teacher who receives a notification email anytime a student enrolls in a course (via PayPal enrollment).
The email contents come from lang/en/enrol.php:
$string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}";
What I'm trying to do is include the student's email address in this, for the teacher to reference.
Here's what I've tried:
$string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}". Student\'s email address: {$a->email}';
To make this $a->email variable available, I went into the function that gets the email contents: enrol/flatfile/lib.php::process_records()
Inside process_records(), I added the following:
$a->email = $user->email;
I put this directly after these lines:
$a = new stdClass();
$a->course = format_string($course->fullname, true, array('context' => $context));
$a->user = fullname($user);
and before this line, which gets the email contents:
$eventdata->fullmessage = get_string('enrolmentnewuser', 'enrol', $a);
I would think that the $a object would now contain my new 'email' property, which would be accessible in the 'enrolmentnewuser' string.
I've cleared the cache after my updates.
Unfortunately, this is the email the teacher is now receiving:
Student has enrolled in course "Test Course". Student's email address: {$a->email}
It looks like the $a->email is not swapping the actual property into the message. For the life of me, I haven't been able to figure out why it's not working. It's been difficult to debug, as I have to keep enrolling and un-enrolling in the test course which is frustrating.
Does anyone have any insight into why this is printing the $a->email property name literally, instead of the actual property?
In your case, you need to add the below line to enrol/paypal/ipn.php file also.
$a->email = $user->email;
put this directly after these lines:
$a->course = format_string($course->fullname, true, array('context' => $coursecontext));
$a->user = fullname($user);

Laravel custom validation rule on valid email

So basically I have a simple form and one of the fields is an email.
My controller responsible for this form is the following(showing only the essentials)
$messages = array(
'rsvp_email.required' => 'A valid email is required.')
);
$rules = array(
'rsvp_email' => 'required|max:150|email',
);
$validator = Validator::make($request->all(), $rules,$messages);
Now there are 2 scenarios:
a) The email is not inserted and the above validation works with the custom message(This works OK)
b) The email is not in a valid format (myemail#email) and the resulted error message is The rsvp email must be a valid email address. which is not what I want to be displayed.
What additional rule should I include for a valid email?
Thank
IF you want to change this message go to the following path:
resources/lang/en/validation.php
and change value of email index.

How to send mail to multiple recipients in Yii2 mailer

This code is working for a single recipient but not for multiple recipients.How should I add multiple recipient into send() function in here.
//find price
$price = MDealPrice::model()->find("id=:id", array(':id' => $id));
// find deal
$deal = MDeal::model()->find("id=:id", array(':id' => $price->dealId));
//send email
app()->mailer->send($sendEmailAdd, 'orderAuthorizeEmail', array('deal' => $deal));
I tried like this also, But not worked.
//send email
app()->mailer->send(array('email1#domain.com','email2#domain.com'), 'orderAuthorizeEmail', array('deal' => $deal));
Thanks in advance!
Please try with below solution it will work
app()->mailer->send('email1#domain.com,email2#domain.com', 'orderAuthorizeEmail', array('deal' => $deal));
just add your email ids comma separated string in send function instead to pass array of email ids.

How to send mailgun email from form?

I would like to use a form to send a verification email though mailgun to users when they sign up for a service. I have a form collecting the required info for the email but need to put it into the email. The problem is the way the email is formatted and I do not know how to print the data.
Here is my action:
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mgClient = new Mailgun('MY-API-KEY');
$domain = "https://api.mailgun.net/v3/MY-DOMAIN";
$result = $mgClient->sendMessage($domain, array(
'from' => 'Verifier <MY-ADDRESS>',
'to' => '<?php print_r(GET_$[email]) ?>, second-address#email.com',
'subject' => 'Verifcation & Instructions',
'text' => 'Dear print_r(GET_$[username]),
Thank you for requesting a service for print_r(GET_$[url]).
To make sure this was you, please click here and verify ...'
));
?>
I know the send is working because of the second address I have set up.
Thanks for any help!
Here is a possible solution as given to me by Mailgun Support:
http://blog.mailgun.com/double-opt-in-with-php-mailgun/

Categories