Combine variable and text creating email address?

the mail() function

Moderators: macek, egami, gesf

csf7roa
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Apr 18, 2011 11:00 am

Combine variable and text creating email address?

Postby csf7roa » Mon Apr 18, 2011 11:08 am

Hi,

I would really appreciate help with the following.

I am trying to combine a variables value with text in order to form an email address to use in the mail function.

I have tried the following code:

Code: Select all

$email = '$start@email.uk';
$to = $email;


The variable '$start' contains only the start of an email address before the '@' symbol (e.g. emailstart) and I want to combine this with the text '@email.uk' in order to form the complete email address 'emailstart@email.uk'.

The above code does not work in combining these and I have also tried using the '+' symbol between them but to no avail. Has anyone got any ideas?

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Combine variable and text creating email address?

Postby Nullsig » Mon Apr 18, 2011 11:16 am

Code: Select all

$email = $start . '@email.uk';
$to = $email;

csf7roa
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Apr 18, 2011 11:00 am

Re: Combine variable and text creating email address?

Postby csf7roa » Mon Apr 18, 2011 11:25 am

Brilliant!

Works fine.

Many Thanks! :D

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Combine variable and text creating email address?

Postby egami » Mon Apr 18, 2011 11:48 am

you could have avoided the whole riggamora of that thing by just stating:


$to = "$start@email.uk";

here's why it didn't work.

$email = '$start@email.uk';
This single tick blocks transformation of variables to strings in output.
Using double quotes " " will transform variables to strings in output.

$to = $email;
An un-needed, unnecessary step. creating two variables with the exact same information is ... you get the idea.

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Combine variable and text creating email address?

Postby Nullsig » Tue Apr 19, 2011 5:25 am

You are correct egami. But I felt teaching that "." is the method of concatenation is more important then stressing the difference in parsing between single and double quoted strings.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Combine variable and text creating email address?

Postby egami » Tue Apr 19, 2011 7:45 am

No question or qualms there :)
I was adding to your comment, not trying to change it

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Combine variable and text creating email address?

Postby Nullsig » Tue Apr 19, 2011 8:18 am

Didn't mean to come across as hostile... Just wanted to state the reason for my solution to assist csf7roa in understanding what was going on.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Combine variable and text creating email address?

Postby egami » Tue Apr 19, 2011 8:21 am

I don't take the Internet seriously..
Too many others do for me to get involved :)

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Combine variable and text creating email address?

Postby Nullsig » Tue Apr 19, 2011 9:18 am

Image

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Combine variable and text creating email address?

Postby egami » Tue Apr 19, 2011 10:01 am

If that guy was any more serious, he'd be cross-eyed!


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest

cron