find email and replace with a sentence in PHP - str-replace

How do I prevent people from entering their email address in the description field by replacing their email to some wordings, for example if user entered the following text:
Please contact me via joe.joey#email.com.
I want the output to be:
Please contact me via <email address is blocked>.
I know of a basic str_replace but the output would simply be:
//output is Please contact me via joe.joey <email address is blocked> email.com
$string = 'Please contact me via joe.joey#email.com.';
$lookfor = '#';
$replacewith = '<email address is blocked>';
$newstring = str_replace($lookfor, $replacewith, $string);
thanks.

This is a perfect time to use preg_replace. I've slightly simplified the requirements for a valid email here (emails can be horridly complex), but something like:
$newstring = preg_replace("/[\w-]+#([\w-]+\.)+[\w-]+/", $replacewith, $string);

Related

How to add more than 1000 email address using mail_to

Currently i have the below code in index view
<div id = "GetEmails"><%= mail_to "xyz#gmail.com" do %><strong>Send Mail</strong><% end %></div>
In runtime, I am updating the value of mailto: which consists of more than 1000
+email address
Now, when I click on "Send Mail", outlook is not getting opened by copying all the email address in To: field
But, if the number of email address are < 100, the on click of "Send Mail" I am able to copy all the email address in To: filed
Manually, I am able to copy more than 3000 email address.
How do I get copy all the email address in To line by clicking "Send Mail".
The mailto:(as any other URL) has a character limit for the URL, it's vary from browser to browser, or from E-Mail client to E-Mail client.
Please try to use JS.
You could have a HTML element with data attribute where all emails would be stored and then try this:
<div id="my-mails-storing-element-id" data-mails="person1#domain.com, person2#domain.com,person3#domain.com"></div>
var mailsDom = document.getElementById("my-mails-storing-element-id")
location.href = mailto:mailsDom.dataset.mails;
But it would be better if you create separate action in your controller to get those emails. Then you just need to make AJAX call to get mails data.
I hope it'd help you. Please let me now if it worked (I've tried with Mailspring mail client and it worked)

Why is Entrez email address not specified in biopython even if given my NCBI log-in email?

UserWarning:
Email address is not specified.
To make use of NCBI's E-utilities, NCBI requires you to specify your
email address with each request. As an example, if your email address
is A.N.Other#example.com, you can specify it as follows:
from Bio import Entrez
Entrez.email = 'A.N.Other#example.com'
In case of excessive usage of the E-utilities, NCBI will attempt to contact
a user at the email address provided before blocking access to the
E-utilities.
E-utilities.""", UserWarning)
Issue code:
importing SeqIO, Entrez
Entrez.mai l= "rubayet#example.com" with Entrez.efetch(db="nucleotide",rettype="fasta",retmode="text"‌​,id="AF191665.1") as handle: a=SeqIO.read(handle,"fasta") print(a.description)
Solution:
replace Entrez.mai l= "rubayet#example.com"
with the following code:
Entrez.email = 'rubayet#example.com'
Note: Posting BioGeeks answer for the sake of getting this question out of the questionlist.

email url hostname parse php

I'm trying to parse the hostname url inside my php to get an email, but I'm not getting the url hostname. See the code below. I do not know what I'm doing wrong here. {$baseURL}
// hostname variable
$baseURL = $SERVER['SERVERNAME'];
$message_contents = "Greetings ".trim($fullName).".\n\nPlease follow the link below to reset your password.\n\n{$baseURL}/ssp/resetssp.php?token=".$token."\n\n(*Please do not reply to this email.)\n\nIf you did not request that your password be changed.\n\nThank you,";
Here is the email I'm getting without the hostname parse.
/ssp/resetssp.php?token=WF5IMKKT7AZCV5V19CRKSWWCA7PM7PCE
I would like to get the output like this:
https://domainname/ssp/resetssp.php?token=WF5IMKKT7AZCV5V19CRKSWWCA7PM7PCE
You can use $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST'] depends on what you need. This article explains the difference between them: SERVER_NAME Versus HTTP_HOST. So, try using this code:
// hostname variable
$baseURL = $_SERVER['SERVER_NAME'];
$message_contents = "Greetings ".trim($fullName).".\n\nPlease follow the link below to reset your password.\n\n{$baseURL}/ssp/resetssp.php?token=".$token."\n\n(*Please do not reply to this email.)\n\nIf you did not request that your password be changed.\n\nThank you,";

Read Gmail XOAUTH mails without marking it read

I'm trying to read email from GMail using gmail-xoauth Gem. I want to read the email and leave its unread status.
First, I tried reading just the header. Works.
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.authenticate('XOAUTH2', email, access_token)
imap.select('INBOX')
imap.search(["SINCE", since]).each do |message_id|
msg = imap.fetch(message_id,'RFC822.HEADER')[0].attr['RFC822.HEADER']
mail = Mail.read_from_string msg
puts mail.subject
end
Now, I want to read the body/text of the Email without marking it read.
This maybe be very late but I will leave it here for anyone else that stumbles onto this. If, for what ever reason you want to read the email and leave the flags intake, use:
imap.examine('INBOX')
instead of:
imap.select('INBOX')
From the Net::IMAP doc
Sends a EXAMINE command to select a mailbox so that messages in the mailbox can be accessed. Behaves the same as select(), except that the selected mailbox is identified as read-only.
Based on the documentation you need to use the store method. The documentation mentions:
store(set, attr, flags)
Sends a STORE command to alter data associated with messages in the mailbox, in particular their flags. The set parameter is a number or an array of numbers or a Range object. Each number is a message sequence number. attr is the name of a data item to store: ‘FLAGS’ means to replace the message’s flag list with the provided one; ‘+FLAGS’ means to add the provided flags; and ‘-FLAGS’ means to remove them. flags is a list of flags.
The return value is an array of Net::IMAP::FetchData. For example:
p imap.store(6..8, "+FLAGS", [:Deleted])
#=> [#<Net::IMAP::FetchData seqno=6, attr={"FLAGS"=>[:Seen, :Deleted]}>, \\
#<Net::IMAP::FetchData seqno=7, attr={"FLAGS"=>[:Seen, :Deleted]}>, \\
#<Net::IMAP::FetchData seqno=8, attr={"FLAGS"=>[:Seen, :Deleted]}>]
So you have to remove the :Seen flag
imap.store(message_id, "-FLAGS", [:Seen])

Sending formatted/html Outlook email with Ruby Win32ole

Is it possible to send formatted email, whether html or otherwise with Ruby's WIN32OLE - I have been able to send a plain text email through automation (as follows), but was hoping to be able to add some formatting. Any help would be greatly appreciated!
require 'win32ole'
#outlook = WIN32OLE.new('Outlook.Application')
email = #outlook.CreateItem(0)
email.Subject = 'Test Subject'
email.Body = 'Test Body'
email.To = 'recipient#example.com'
email.Save
email.Send
Pretty sure you need to use HTMLBody instead of Body as in:
email.HTMLBody = '<h3>Test body in HTML format</h3>'

Resources